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()