From 51a68f87f7b2b6f4ffaa53552597eb68335da72d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 14 Sep 2025 10:22:46 +0000 Subject: [PATCH] fix(cli): restrict --progress flag to GET command The --progress flag was previously available for all commands, but it is only implemented for GET requests. This could be confusing for users. This commit moves the --progress argument from the common arguments to the GET parser, so it is only available for GET requests. A new test case has been added to verify that the --progress flag is not available for commands other than GET. --- PyFetch/cli.py | 16 ++++++++-------- tests/test_cli.py | 12 ++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/PyFetch/cli.py b/PyFetch/cli.py index a68da0c..b3906ef 100644 --- a/PyFetch/cli.py +++ b/PyFetch/cli.py @@ -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.""" @@ -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( @@ -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: diff --git a/tests/test_cli.py b/tests/test_cli.py index 9de6a49..f398a68 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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()