/
entrypoint.py
85 lines (78 loc) · 2.4 KB
/
entrypoint.py
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
import logging
import sys
import click
from rich.console import Console
from .analyzer import ResourcesAnalyzer
from .app import Application
from .files import FilesHandler
from .reporting import Reporter, CsvAnalysisReporter, StdoutReporter
from .resources import ResourcesFetcher, ResourcesModifier
from .validator import Validator
LIB_PROJECT_HELP = (
"The path to the android project whose resources you want to inspect."
)
CLIENT_PROJECT_HELP = (
"The path to the client android project that consumes the reference"
" project resources"
)
@click.command()
@click.option(
"--app",
type=click.Path(resolve_path=True, exists=True, file_okay=False),
required=True,
help=LIB_PROJECT_HELP,
)
@click.option(
"--client",
type=click.Path(resolve_path=True, exists=True, file_okay=True),
multiple=True,
required=False,
help=CLIENT_PROJECT_HELP,
)
@click.option(
"--reports-dir",
type=click.Path(resolve_path=True, exists=True, file_okay=False),
required=False,
default=".",
help="The directory where the csv reports will be written.",
)
@click.option(
"--check",
is_flag=True,
default=False,
help="Using this flag will fail the execution if any unused resources are found",
)
@click.option(
"--report",
type=click.Choice(["CSV", "STDOUT"], case_sensitive=False),
required=False,
)
@click.option(
"--delete",
is_flag=True,
default=False,
help="Using this flag will automatically delete the unused resources",
)
def launch(app, client, report, reports_dir, check, delete):
try:
console = Console()
error_console = Console(stderr=True, style="bold red")
stdout_reporter = StdoutReporter(console)
csv_reporter = CsvAnalysisReporter(console, reports_dir)
choice_reporters = {
None: [stdout_reporter, csv_reporter],
"CSV": [csv_reporter],
"STDOUT": [stdout_reporter],
}
application = Application(
resources_fetcher=ResourcesFetcher(FilesHandler()),
resources_modifier=ResourcesModifier(),
analyzer=ResourcesAnalyzer(),
reporter=Reporter(console, error_console, choice_reporters[report]),
validator=Validator(),
)
application.execute(app, client, check, delete)
sys.exit(0)
except Exception:
logging.exception("Could not complete analysis.")
sys.exit(1)