-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
95 lines (87 loc) · 3.69 KB
/
Copy pathcli.py
File metadata and controls
95 lines (87 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from __future__ import annotations
import argparse
import json
import os
import sys
from .tester import run_assess_distribution, run_benchmark, run_test_project
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(prog="featurevisor")
subparsers = parser.add_subparsers(dest="command", required=True)
common = argparse.ArgumentParser(add_help=False)
common.add_argument("--projectDirectoryPath", default=os.getcwd())
common.add_argument("--environment")
common.add_argument("--feature")
common.add_argument("--context")
common.add_argument("--keyPattern")
common.add_argument("--assertionPattern")
common.add_argument("--onlyFailures", action="store_true")
common.add_argument("--quiet", action="store_true")
common.add_argument("--verbose", action="store_true")
common.add_argument("--showDatafile", action="store_true")
common.add_argument("--variation", action="store_true")
common.add_argument("--variable")
common.add_argument("--n", type=int, default=1000)
common.add_argument("--inflate", type=int, default=0)
common.add_argument("--with-scopes", "--withScopes", dest="with_scopes", action="store_true")
common.add_argument("--with-tags", "--withTags", dest="with_tags", action="store_true")
common.add_argument("--schemaVersion", "--schema-version", dest="schema_version")
common.add_argument("--populateUuid", action="append", default=[])
common.add_argument("--target", action="append", default=[])
subparsers.add_parser("test", parents=[common])
subparsers.add_parser("benchmark", parents=[common])
subparsers.add_parser("assess-distribution", parents=[common])
return parser
def main(argv: list[str] | None = None) -> int:
parser = build_parser()
args = parser.parse_args(argv)
context = json.loads(args.context) if args.context else {}
if args.command == "test":
ok = run_test_project(
args.projectDirectoryPath,
key_pattern=args.keyPattern,
assertion_pattern=args.assertionPattern,
verbose=args.verbose,
quiet=args.quiet,
show_datafile=args.showDatafile,
only_failures=args.onlyFailures,
schema_version=args.schema_version,
inflate=args.inflate,
with_scopes=args.with_scopes,
with_tags=args.with_tags,
targets=args.target,
)
return 0 if ok else 1
if args.command == "benchmark":
if not args.environment or (not args.feature and not args.variable) or (args.variation and not args.feature):
parser.error("benchmark requires --environment and either --feature or --variable")
return run_benchmark(
args.projectDirectoryPath,
environment=args.environment,
feature=args.feature,
context=context,
n=args.n,
variation=args.variation,
variable=args.variable,
inflate=args.inflate,
verbose=args.verbose,
quiet=args.quiet,
targets=args.target,
)
if args.command == "assess-distribution":
if not args.environment or not args.feature:
parser.error("assess-distribution requires --environment and --feature")
return run_assess_distribution(
args.projectDirectoryPath,
environment=args.environment,
feature=args.feature,
context=context,
n=args.n,
populate_uuid=args.populateUuid,
inflate=args.inflate,
verbose=args.verbose,
quiet=args.quiet,
targets=args.target,
)
return 1
if __name__ == "__main__":
sys.exit(main())