Revision 26cd03ca kamaki/cli/commands/config_cli.py

b/kamaki/cli/commands/config_cli.py
32 32
# or implied, of GRNET S.A.
33 33

  
34 34
from kamaki.cli import command#, set_api_description
35
from kamaki.cli.argument import FlagArgument
35 36
#set_api_description('config', 'Configuration commands')
36 37
API_DESCRIPTION = {'config':'Configuration commands'}
37 38

  
39
class _config_init(object):
40
    def __init__(self, arguments={}):
41
        self.arguments=arguments
42
        try:
43
            self.config = self.get_argument('config')
44
        except KeyError:
45
            pass
46

  
47
    def get_argument(self, arg_name):
48
        return self.arguments[arg_name].value
49

  
38 50
@command()
39
class config_list(object):
51
class config_list(_config_init):
40 52
    """List configuration options"""
41 53

  
42
    def update_parser(self, parser):
43
        parser.add_argument('-a', dest='all', action='store_true',
44
                          default=False, help='include default values')
54
    def __init__(self, arguments={}):
55
        super(config_list, self).__init__(arguments)
56
        self.arguments['all'] = FlagArgument('include default values', '-a')
45 57

  
46 58
    def main(self):
47
        include_defaults = self.args.all
59
        include_defaults = self.get_argument('all')
48 60
        for section in sorted(self.config.sections()):
49 61
            items = self.config.items(section, include_defaults)
50 62
            for key, val in sorted(items):
51 63
                print('%s.%s = %s' % (section, key, val))
52 64

  
53 65
@command()
54
class config_get(object):
66
class config_get(_config_init):
55 67
    """Show a configuration option"""
56 68

  
57 69
    def main(self, option):
......
62 74
            print(value)
63 75

  
64 76
@command()
65
class config_set(object):
77
class config_set(_config_init):
66 78
    """Set a configuration option"""
67 79

  
68 80
    def main(self, option, value):
......
72 84
        self.config.write()
73 85

  
74 86
@command()
75
class config_delete(object):
87
class config_delete(_config_init):
76 88
    """Delete a configuration option (and use the default value)"""
77 89

  
78 90
    def main(self, option):

Also available in: Unified diff