Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions httpie/cli/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ def parse_args(
self.env = env
self.env.args = namespace = namespace or argparse.Namespace()
self.args, no_options = super().parse_known_args(args, namespace)
if self.args.url:
request_items = [
option for option in no_options if not option.startswith('-')
]
if request_items:
request_item_type = KeyValueArgType(*SEPARATOR_GROUP_ALL_ITEMS)
self.args.request_items = [
*(self.args.request_items or []),
*(request_item_type(item) for item in request_items),
]
no_options = [
option for option in no_options
if option.startswith('-')
]
if self.args.debug:
self.args.traceback = True
self.has_stdin_data = (
Expand Down
17 changes: 17 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,23 @@ def test_multiple_text_fields_with_same_field_name(self):
]


class TestIntermixedOptions:
def test_output_option_after_url_keeps_request_items(self):
r = http(
'--offline',
'--ignore-stdin',
'post',
'pie.dev/post',
'-v',
'header1:xyz',
'x=1',
)

assert r.exit_status == ExitStatus.SUCCESS
assert 'header1: xyz' in r
assert '"x": "1"' in r


class TestQuerystring:
def test_query_string_params_in_url(self, httpbin):
r = http('--print=Hhb', 'GET', httpbin + '/get?a=1&b=2')
Expand Down
Loading