Coverage for kiertotie/cli.py: 0.00%
34 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-04 18:44:05 +00:00
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-04 18:44:05 +00:00
1"""Command line interface for detour (Finnish: kiertotie) per rsync proxy to https mirror node.."""
3import argparse
4import pathlib
5import sys
6from typing import List, Union
8import kiertotie.dispatch as dispatch
9from kiertotie import APP_ALIAS, APP_NAME
12def parse_request(argv: List[str]) -> Union[int, argparse.Namespace]:
13 """DRY."""
14 parser = argparse.ArgumentParser(
15 prog=APP_ALIAS, description=APP_NAME, formatter_class=argparse.RawTextHelpFormatter
16 )
17 parser.add_argument(
18 '--proxy',
19 '-p',
20 dest='proxy',
21 required=False,
22 help='proxy data path',
23 )
24 parser.add_argument(
25 'proxy_pos',
26 nargs='?',
27 default='',
28 help='proxy data path',
29 )
30 parser.add_argument(
31 '--updater',
32 '-u',
33 dest='update_path',
34 required=False,
35 default=None,
36 help='update shell script path to write',
37 )
38 parser.add_argument(
39 '--anchor',
40 '-a',
41 dest='anchor_path',
42 required=False,
43 default=None,
44 help='absolute anchor path (webroot) below which we mirror',
45 )
46 parser.add_argument(
47 '--span-tree',
48 '-s',
49 dest='span_folder_tree',
50 default=False,
51 action='store_true',
52 help='span the folder tree from proxy data',
53 )
54 parser.add_argument(
55 '--verbose',
56 '-v',
57 dest='verbose',
58 default=False,
59 action='store_true',
60 help='be verbose in logging and write status info to shell scripts',
61 )
62 if not argv:
63 parser.print_help()
64 return 0
66 options = parser.parse_args(argv)
68 if not options.proxy:
69 if options.proxy_pos:
70 options.proxy = options.proxy_pos
71 else:
72 options.proxy = str(pathlib.Path.cwd())
74 proxy = pathlib.Path(options.proxy)
75 if proxy.exists():
76 if proxy.is_file():
77 return options
78 parser.error(f'requested proxy data path ({proxy}) is no file')
80 parser.error(f'requested proxy data path ({proxy}) does not exist')
83def main(argv: Union[List[str], None] = None) -> int:
84 """Delegate processing to functional module."""
85 argv = sys.argv[1:] if argv is None else argv
86 options = parse_request(argv)
87 if isinstance(options, int):
88 return 0
89 return dispatch.verify(options)