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
|
import argparse
import json
from dataclasses import dataclass
from typing import Optional
@dataclass
class LinterArgs:
source_root: str
project_path: str
output_path: str
depends: dict[str, str]
configs: list[str]
report_file: str
files: list[str]
def get_params(raw_args: Optional[list[str]] = None) -> LinterArgs:
parser = argparse.ArgumentParser()
parser.add_argument("--params")
parser.add_argument("--source-root")
parser.add_argument("--project-path")
parser.add_argument("--output-path")
parser.add_argument("--depends", action="append")
parser.add_argument("--configs", action="append")
parser.add_argument("--report-file", default="-")
parser.add_argument("files", nargs="*")
args = parser.parse_args(raw_args)
if args.params:
with open(args.params) as f:
params = json.load(f)
source_root = params["source_root"]
project_path = params["project_path"]
output_path = params["output_path"]
depends = params.get("depends", {})
configs = params.get("configs", [])
report_file = params["report_file"]
files = params["files"]
else:
source_root = args.source_root
project_path = args.project_path
output_path = args.output_path
depends = {}
if args.depends:
for dep in args.depends:
rel_path, abs_path = dep.split(":", 1)
depends[rel_path] = abs_path
configs = args.configs if args.configs else []
report_file = args.report_file
files = args.files
return LinterArgs(
source_root=source_root,
project_path=project_path,
output_path=output_path,
depends=depends,
configs=configs,
report_file=report_file,
files=files,
)
|