Initial commit
[ta/distributed-state-server.git] / src / dss / cli / dss_cliprocessors.py
1 # Copyright 2019 Nokia
2 #
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
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
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 #
15
16 import sys
17 import argparse
18
19 from dss.cli import dss_clihandlers
20
21 class CLIProcessor:
22     def __init__(self, prog):
23         self.prog = prog
24
25     def __call__(self, args):
26         parser = argparse.ArgumentParser(description='dss CLI', prog=self.prog)
27         parser.add_argument('--server', 
28                 dest='server',
29                 metavar='SERVER',
30                 default='/var/run/.dss-server',
31                 type=str, 
32                 action='store')
33
34         parser.add_argument('--verbose',
35                 required=False,
36                 default=False,
37                 action='store_true')
38
39         subparsers = parser.add_subparsers()
40         handlers = dss_clihandlers.get_handlers_list()
41         for handler in handlers:
42             handler.init_subparser(subparsers)
43
44         parse_result = parser.parse_args(args)
45
46         parse_result.handler(parse_result)
47
48
49 if __name__ == '__main__':
50     processor = CLIProcessor('dsscli')
51     args = sys.argv[1:]
52     try:
53         processor(args)
54     except Exception as error:
55         print('Got error %s' % str(error))
56         sys.exit(1)
57