Coverage for suhteita/cli.py: 100.00%
19 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-04 22:42:46 +00:00
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-04 22:42:46 +00:00
1#! /usr/bin/env python
2"""CLI operations for relationships (Finnish: suhteita) maintained across distances as load test core."""
3import argparse
4import sys
5from typing import List, Union
7import suhteita.suhteita as api
8from suhteita import APP_ALIAS, APP_ENV, BASE_URL, IDENTITY, IS_CLOUD, PROJECT, STORE, USER
11def parse_request(argv: List[str]) -> argparse.Namespace:
12 """DRY."""
13 parser = argparse.ArgumentParser(description=APP_ALIAS)
14 parser.add_argument(
15 '--user',
16 '-u',
17 dest='user',
18 default=USER,
19 help=f'user (default: {USER if USER else f"None, set {APP_ENV}_USER for default"})',
20 )
21 parser.add_argument(
22 '--target',
23 '-t',
24 dest='target_url',
25 default=BASE_URL,
26 help=f'target URL (default: {BASE_URL if BASE_URL else f"None, set {APP_ENV}_BASE_URL for default"})',
27 )
28 parser.add_argument(
29 '--is-cloud',
30 action='store_true',
31 dest='is_cloud',
32 default=IS_CLOUD,
33 help=(
34 'target is cloud instance (default: '
35 f'{"True" if IS_CLOUD else f"False, set {APP_ENV}_IS_CLOUD for a different default"})'
36 ),
37 )
38 parser.add_argument(
39 '--project',
40 '-p',
41 dest='target_project',
42 default=PROJECT,
43 help=f'target project (default: {PROJECT if PROJECT else f"None, set {APP_ENV}_PROJECT for default"})',
44 )
45 parser.add_argument(
46 '--scenario',
47 '-s',
48 dest='scenario',
49 default='unknown',
50 help='scenario for recording (default: unknown)',
51 )
52 parser.add_argument(
53 '--identity',
54 '-i',
55 dest='identity',
56 default=IDENTITY if IDENTITY else 'adhoc',
57 help=(
58 'identity of take for recording'
59 f' (default: {IDENTITY if IDENTITY else f"adhoc, set {APP_ENV}_IDENTITY for default"})'
60 ),
61 )
62 parser.add_argument(
63 '--out-path',
64 '-o',
65 dest='out_path',
66 default=STORE if STORE else 'store',
67 help=(
68 'output folder path for recording'
69 f' (default: {STORE if STORE else f"store, set {APP_ENV}_STORE for default"})'
70 ),
71 )
72 return parser.parse_args(argv)
75# pylint: disable=expression-not-assigned
76def main(argv: Union[List[str], None] = None) -> int:
77 """Delegate processing to functional module."""
78 argv = sys.argv[1:] if argv is None else argv
80 return api.main(parse_request(argv))