diff --git a/httpie/cli/definition.py b/httpie/cli/definition.py index 3d5650c007..f18d8e35ee 100644 --- a/httpie/cli/definition.py +++ b/httpie/cli/definition.py @@ -66,8 +66,8 @@ $ http example.org hello=world # => POST """, -).completer = ChoicesCompleter( - ('GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS')) + completer=ChoicesCompleter(('GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS')) +) positional_arguments.add_argument( dest='url', metavar='URL', @@ -82,7 +82,8 @@ $ http :/foo # => http://localhost/foo """, -).completer = ChoicesCompleter(()) + completer=ChoicesCompleter(()), +) positional_arguments.add_argument( dest='request_items', metavar='REQUEST_ITEM', @@ -139,7 +140,8 @@ field-name-with\:colon=value """, -).completer = ChoicesCompleter(()) + completer=ChoicesCompleter(()), +) ####################################################################### # Content type. @@ -192,8 +194,9 @@ short_help=( 'Specify a custom boundary string for multipart/form-data requests. ' 'Only has effect only together with --form.' - ) -).completer = ChoicesCompleter(()) + ), + completer=ChoicesCompleter(()), +) content_types.add_argument( '--raw', short_help='Pass raw request data without extra processing.', @@ -354,7 +357,8 @@ def format_style_help(available_styles, *, isolation_mode: bool = False): --response-charset=big5 """, -).completer = ChoicesCompleter(()) + completer=ChoicesCompleter(()), +) output_processing.add_argument( '--response-mime', metavar='MIME_TYPE', @@ -367,7 +371,8 @@ def format_style_help(available_styles, *, isolation_mode: bool = False): --response-mime=text/xml """, -).completer = ChoicesCompleter(()) + completer=ChoicesCompleter(()), +) output_processing.add_argument( '--format-options', action='append', @@ -392,7 +397,8 @@ def format_style_help(available_styles, *, isolation_mode: bool = False): f' {option}' for option in DEFAULT_FORMAT_OPTIONS ).strip() ), -).completer = ChoicesCompleter(()) + completer=ChoicesCompleter(()), +) ####################################################################### # Output options @@ -421,7 +427,8 @@ def format_style_help(available_styles, *, isolation_mode: bool = False): response body is printed by default. """, -).completer = ChoicesCompleter(()) + completer=ChoicesCompleter(()), +) output_options.add_argument( '--headers', '-h', @@ -495,7 +502,8 @@ def format_style_help(available_styles, *, isolation_mode: bool = False): dest='output_options_history', metavar='WHAT', help=Qualifiers.SUPPRESS, -).completer = ChoicesCompleter(()) + completer=ChoicesCompleter(()), +) output_options.add_argument( '--stream', '-S', @@ -529,7 +537,8 @@ def format_style_help(available_styles, *, isolation_mode: bool = False): printed to stderr. """, -).completer = FilesCompleter() + completer=FilesCompleter(), +) output_options.add_argument( '--download', @@ -600,7 +609,8 @@ def format_style_help(available_styles, *, isolation_mode: bool = False): https://httpie.io/docs/cli/config-file-directory """, -).completer = FilesCompleter(('json',)) + completer=FilesCompleter(('json',)), +) sessions.add_argument( '--session-read-only', metavar='SESSION_NAME_OR_PATH', @@ -611,7 +621,8 @@ def format_style_help(available_styles, *, isolation_mode: bool = False): exchange. """, -).completer = FilesCompleter(('json',)) + completer=FilesCompleter(('json',)), +) ####################################################################### # Authentication @@ -675,7 +686,8 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False): (-a username), HTTPie will prompt for the password. """, -).completer = ChoicesCompleter(()) + completer=ChoicesCompleter(()), +) authentication.add_argument( '--auth-type', '-A', @@ -686,7 +698,8 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False): cache=False, short_help='The authentication mechanism to be used.', help_formatter=format_auth_help, -).completer = ChoicesCompleter(()) + completer=ChoicesCompleter(()), +) authentication.add_argument( '--ignore-netrc', default=False, @@ -720,7 +733,8 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False): and $HTTPS_proxy are supported as well. """, -).completer = ChoicesCompleter(()) + completer=ChoicesCompleter(()), +) network.add_argument( '--follow', '-F', @@ -738,7 +752,8 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False): By default, requests have a limit of 30 redirects (works with --follow). """, -).completer = ChoicesCompleter(()) + completer=ChoicesCompleter(()), +) network.add_argument( '--max-headers', type=int, @@ -746,8 +761,9 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False): short_help=( 'The maximum number of response headers to be read before ' 'giving up (default 0, i.e., no limit).' - ) -).completer = ChoicesCompleter(()) + ), + completer=ChoicesCompleter(()), +) network.add_argument( '--timeout', @@ -764,7 +780,8 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False): the underlying socket for timeout seconds). """, -).completer = ChoicesCompleter(()) + completer=ChoicesCompleter(()), +) network.add_argument( '--check-status', default=False, @@ -814,7 +831,8 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False): for private certs. (Or you can set the REQUESTS_CA_BUNDLE environment variable instead.) """, -).completer = ChoicesCompleter(('yes', 'no')) + completer=ChoicesCompleter(('yes', 'no')), +) ssl.add_argument( '--ssl', dest='ssl_version', @@ -828,7 +846,8 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False): are shown here). """, -).completer = ChoicesCompleter(()) + completer=ChoicesCompleter(()), +) ssl.add_argument( '--ciphers', short_help='A string in the OpenSSL cipher list format.', @@ -840,7 +859,8 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False): {DEFAULT_SSL_CIPHERS} """, -).completer = ChoicesCompleter(()) + completer=ChoicesCompleter(()), +) ssl.add_argument( '--cert', default=None, @@ -852,7 +872,8 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False): specify --cert-key separately. """, -).completer = FilesCompleter(('crt', 'cert', 'pem')) + completer=FilesCompleter(('crt', 'cert', 'pem')), +) ssl.add_argument( '--cert-key', default=None, @@ -863,7 +884,8 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False): certificate file does not contain the private key. """, -).completer = FilesCompleter(('key', 'pem')) + completer=FilesCompleter(('key', 'pem')), +) ssl.add_argument( '--cert-key-pass', @@ -874,8 +896,9 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False): The passphrase to be used to with the given private key. Only needed if --cert-key is given and the key file requires a passphrase. If not provided, you’ll be prompted interactively. - """ -).completer = ChoicesCompleter(()) + """, + completer=ChoicesCompleter(()), +) ####################################################################### # Troubleshooting @@ -916,8 +939,9 @@ def format_auth_help(auth_plugins_mapping, *, isolation_mode: bool = False): troubleshooting.add_argument( '--default-scheme', default='http', - short_help='The default scheme to use if not specified in the URL.' -).completer = ChoicesCompleter(('http', 'https')) + short_help='The default scheme to use if not specified in the URL.', + completer=ChoicesCompleter(('http', 'https')), +) troubleshooting.add_argument( '--debug', action='store_true', diff --git a/httpie/cli/options.py b/httpie/cli/options.py index c06a8ee615..3fe8ed7858 100644 --- a/httpie/cli/options.py +++ b/httpie/cli/options.py @@ -187,7 +187,7 @@ def __getattr__(self, attribute_name): Qualifiers.ZERO_OR_MORE: argparse.ZERO_OR_MORE, Qualifiers.ONE_OR_MORE: argparse.ONE_OR_MORE } -ARGPARSE_IGNORE_KEYS = ('short_help', 'nested_options') +ARGPARSE_IGNORE_KEYS = ('short_help', 'nested_options', 'completer') def to_argparse( @@ -211,12 +211,14 @@ def to_argparse( concrete_group = concrete_group.add_mutually_exclusive_group(required=False) for abstract_argument in abstract_group.arguments: - concrete_group.add_argument( + argument = concrete_group.add_argument( *abstract_argument.aliases, **drop_keys(map_qualifiers( abstract_argument.configuration, ARGPARSE_QUALIFIER_MAP ), ARGPARSE_IGNORE_KEYS) ) + if 'completer' in abstract_argument.configuration: + argument.completer = abstract_argument.configuration['completer'] return concrete_parser