Coverage for src\zapy\cli.py: 0%

1 import sys

2 import textwrap

3 import argparse

4

5

6 class ZapyCLI:

7

8 def __init__(self):

9 parser = argparse.ArgumentParser(

10 description='Zapy CLI',

11 usage=textwrap.dedent('''\

12 zapy <command> [<args>]

13 The most commonly used git commands are:

14 start_server Start the zapy service

15 connection Read or create connection config

16 ''')

17 )

18 parser.add_argument('command', help='Subcommand to run')

19 # parse_args defaults to [1:] for args, but you need to

20 # exclude the rest of the args too, or validation will fail

21 args = parser.parse_args(sys.argv[1:2])

22 if not hasattr(self, args.command):

23 print('Unrecognized command')

24 parser.print_help()

25 exit(1)

26 # use dispatch pattern to invoke method with same name

27 getattr(self, args.command)()

28 exit(0)

29

30 def start_server(self):

31 parser = argparse.ArgumentParser(description='Start the zapy service')

32 args = parser.parse_args(sys.argv[2:])

33 from zapy.api.bootstrapper import start_server

34

35 start_server()

36

37 def connection(self):

38 parser = argparse.ArgumentParser(description='Read or create connection')

39 args = parser.parse_args(sys.argv[2:])

40 from zapy.api import connection

41

42 conn_config = connection.load_server_config()

43

44 print(conn_config.model_dump_json())