Revision f3e94e06 kamaki/cli/argument.py
b/kamaki/cli/argument.py | ||
---|---|---|
200 | 200 |
lines.append(line) |
201 | 201 |
return lines |
202 | 202 |
|
203 |
class KeyValueArgument(ValueArgument): |
|
204 |
def __init__(self, help='', parsed_name=None, default={}): |
|
205 |
super(KeyValueArgument,self).__init__(help, parsed_name, default) |
|
206 |
|
|
207 |
@property |
|
208 |
def value(self): |
|
209 |
return super(KeyValueArgument, self).value |
|
210 |
@value.setter |
|
211 |
def value(self, keyvalue_pairs): |
|
212 |
if keyvalue_pairs == self.default: |
|
213 |
return |
|
214 |
if isinstance(keyvalue_pairs, str): |
|
215 |
keyvalue_pairs = keyvalue_pairs.trim().split(' ') |
|
216 |
self._value = self.default |
|
217 |
for pair in keyvalue_pairs: |
|
218 |
key,sep,val = pair.partition('=') |
|
219 |
if not sep: |
|
220 |
raise CLISyntaxError(details='Missing "="" ( "key1=val1 key2=val2 ..."') |
|
221 |
self._value[key.trim()] = val.trim() |
|
222 |
|
|
203 | 223 |
_arguments = dict(config = _config_arg, help = Argument(0, 'Show help message', ('-h', '--help')), |
204 | 224 |
debug = FlagArgument('Include debug output', ('-d', '--debug')), |
205 | 225 |
include = FlagArgument('Include protocol headers in the output', ('-i', '--include')), |
206 | 226 |
silent = FlagArgument('Do not output anything', ('-s', '--silent')), |
207 | 227 |
verbose = FlagArgument('More info at response', ('-v', '--verbose')), |
208 | 228 |
version = VersionArgument('Print current version', ('-V', '--version')), |
209 |
options = CmdLineConfigArgument(_config_arg, 'Override a config vale', ('-o', '--options')), |
|
229 |
options = CmdLineConfigArgument(_config_arg, 'Override a config value', ('-o', '--options')),
|
|
210 | 230 |
history = HistoryArgument('Show user (prefixed) history', '--history') |
211 | 231 |
) |
212 | 232 |
|
Also available in: Unified diff