mirror of
https://github.com/httpie/cli.git
synced 2024-11-24 08:22:22 +02:00
Have --auth prompt for password if omitted.
This commit is contained in:
parent
7bc2de2f9d
commit
929ead437a
@ -123,8 +123,11 @@ parser.add_argument(
|
||||
|
||||
# ``requests.request`` keyword arguments.
|
||||
parser.add_argument(
|
||||
'--auth', '-a', help='username:password',
|
||||
type=cliparse.KeyValueType(cliparse.SEP_COMMON)
|
||||
'--auth', '-a', type=cliparse.AuthCredentials(cliparse.SEP_COMMON),
|
||||
help=_('''
|
||||
username:password.
|
||||
If the password is omitted, HTTPie will prompt for it.
|
||||
'''),
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
|
@ -10,6 +10,7 @@ import argparse
|
||||
import mimetypes
|
||||
|
||||
from collections import namedtuple
|
||||
from getpass import getpass
|
||||
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
@ -204,6 +205,20 @@ class KeyValueType(object):
|
||||
return KeyValue(key=key, value=value, sep=sep, orig=string)
|
||||
|
||||
|
||||
class AuthCredentials(KeyValueType):
|
||||
def __call__(self, string):
|
||||
try:
|
||||
return super(AuthCredentials, self).__call__(string)
|
||||
except argparse.ArgumentTypeError:
|
||||
try:
|
||||
password = getpass("Password for user '%s': " % string)
|
||||
except (EOFError, KeyboardInterrupt):
|
||||
sys.stderr.write('\n')
|
||||
sys.exit(0)
|
||||
return KeyValue(key=string, value=password, sep=SEP_COMMON,
|
||||
orig=string)
|
||||
|
||||
|
||||
def parse_items(items, data=None, headers=None, files=None):
|
||||
"""Parse `KeyValueType` `items` into `data`, `headers` and `files`."""
|
||||
if headers is None:
|
||||
|
Loading…
Reference in New Issue
Block a user