Revision c3d42104 kamaki/cli/argument/__init__.py
b/kamaki/cli/argument/__init__.py | ||
---|---|---|
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 | 34 |
from kamaki.cli.config import Config |
35 |
from kamaki.cli.errors import CLISyntaxError, raiseCLIError |
|
35 |
from kamaki.cli.errors import ( |
|
36 |
CLISyntaxError, raiseCLIError, CLIInvalidArgument) |
|
36 | 37 |
from kamaki.cli.utils import split_input, to_bytes |
37 | 38 |
|
38 | 39 |
from datetime import datetime as dtm |
... | ... | |
375 | 376 |
raiseCLIError(e, 'KeyValueArgument Syntax Error') |
376 | 377 |
|
377 | 378 |
|
379 |
class StatusArgument(ValueArgument): |
|
380 |
"""Initialize with valid_states=['list', 'of', 'states'] |
|
381 |
First state is the default""" |
|
382 |
|
|
383 |
def __init__(self, *args, **kwargs): |
|
384 |
self.valid_states = kwargs.pop('valid_states', ['BUILD', ]) |
|
385 |
super(StatusArgument, self).__init__(*args, **kwargs) |
|
386 |
|
|
387 |
@property |
|
388 |
def value(self): |
|
389 |
return getattr(self, '_value', None) |
|
390 |
|
|
391 |
@value.setter |
|
392 |
def value(self, new_status): |
|
393 |
if new_status: |
|
394 |
new_status = new_status.upper() |
|
395 |
if new_status not in self.valid_states: |
|
396 |
raise CLIInvalidArgument( |
|
397 |
'Invalid argument %s' % new_status, details=[ |
|
398 |
'Usage: ' |
|
399 |
'%s=[%s]' % (self.lvalue, '|'.join(self.valid_states))]) |
|
400 |
self._value = new_status |
|
401 |
|
|
402 |
|
|
378 | 403 |
class ProgressBarArgument(FlagArgument): |
379 | 404 |
"""Manage a progress bar""" |
380 | 405 |
|
Also available in: Unified diff