3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 from __future__ import print_function
18 from cmframework.apis import cmerror
19 from cmframework.cli import cmclihandlers
22 class CMCLIProcessor(object):
23 def __init__(self, prog):
26 def __call__(self, args):
27 parser = argparse.ArgumentParser(description='Configuration Management CLI', prog=self.prog)
28 parser.add_argument('--ip',
31 default='config-manager',
35 parser.add_argument('--port',
37 metavar='SERVER-PORT',
42 parser.add_argument('--client-lib',
45 default='cmframework.lib.CMClientImpl',
49 parser.add_argument('--verbose',
54 subparsers = parser.add_subparsers()
55 handlers = cmclihandlers.get_handlers_list()
56 for handler in handlers:
57 handler.init_subparser(subparsers)
59 parse_result = parser.parse_args(args)
62 parse_result.handler(parse_result)
63 except cmerror.CMError:
65 except Exception as exp:
66 raise cmerror.CMError(str(exp))
70 processor = CMCLIProcessor('cmcli')
74 except cmerror.CMError as error:
75 print('Got error %s' % str(error))
79 if __name__ == '__main__':