Skip to content
Merged
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
16 changes: 8 additions & 8 deletions PyFetch/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ def add_common_arguments(parser):
action="store_true",
help="Enable verbose logging for debugging.",
)
parser.add_argument(
"--progress",
action="store_true",
help="Show progress bar for downloads larger than 5MB",
)


def create_parser():
"""Create an argument parser for the HTTP CLI client."""

Expand Down Expand Up @@ -109,6 +102,11 @@ def _split_lines(self, text, width):
"GET", help="Make a GET request", aliases=["get"]
)
add_common_arguments(get_parser)
get_parser.add_argument(
"--progress",
action="store_true",
help="Show progress bar for downloads larger than 5MB",
)

# POST command
post_parser = subparsers.add_parser(
Expand Down Expand Up @@ -179,7 +177,9 @@ def main(suppress_output=False):
return

client = HTTPClient(
timeout=args.timeout, verbose=args.verbose, show_progress=args.progress
timeout=args.timeout,
verbose=args.verbose,
show_progress=args.progress if hasattr(args, "progress") else False,
)

try:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ def test_post_command(self, mock_post):
main()
mocked_print.assert_called_with("Created")

@patch("PyFetch.http_client.HTTPClient.post")
@patch(
"sys.argv",
["http_cli", "POST", "https://api.example.com", "--progress"],
)
def test_progress_is_not_available_for_post(self, mock_post):
"""Test that --progress is not available for POST command"""
mock_post.return_value.text = "{}"
with self.assertRaises(SystemExit):
with patch('sys.stderr', new_callable=io.StringIO):
main()


if __name__ == "__main__":
unittest.main()