88
99from graphviz import Digraph
1010
11- from .cli_utils import dir_path
11+ from .cli .args import KCLIArgs
12+ from .cli .utils import LOG_FORMAT , dir_path , loglevel
1213from .coverage import get_rule_by_id , strip_coverage_logger
1314from .cterm import split_config_and_constraints
1415from .kast .inner import KInner
2728 from typing import Any , Final
2829
2930
30- _LOG_FORMAT : Final = '%(levelname)s %(asctime)s %(name)s - %(message)s'
3131_LOGGER : Final = logging .getLogger (__name__ )
3232
3333
@@ -40,12 +40,7 @@ def main() -> None:
4040 cli_parser = create_argument_parser ()
4141 args = cli_parser .parse_args ()
4242
43- if not args .verbose :
44- logging .basicConfig (level = logging .WARNING , format = _LOG_FORMAT )
45- elif args .verbose == 1 :
46- logging .basicConfig (level = logging .INFO , format = _LOG_FORMAT )
47- elif args .verbose > 1 :
48- logging .basicConfig (level = logging .DEBUG , format = _LOG_FORMAT )
43+ logging .basicConfig (level = loglevel (args ), format = LOG_FORMAT )
4944
5045 executor_name = 'exec_' + args .command .lower ().replace ('-' , '_' )
5146 if executor_name not in globals ():
@@ -77,7 +72,7 @@ def exec_print(args: Namespace) -> None:
7772 minimized = minimize_term (disjunct , abstract_labels = abstract_labels , keep_cells = keep_cells )
7873 config , constraint = split_config_and_constraints (minimized )
7974 except ValueError as err :
80- raise ValueError ('The minified term does not contain a config cell.' ) from err
75+ raise ValueError ('The minimized term does not contain a config cell.' ) from err
8176
8277 if not is_top (constraint ):
8378 minimized_disjuncts .append (mlAnd ([config , constraint ], sort = GENERATED_TOP_CELL ))
@@ -139,10 +134,7 @@ def exec_json_to_kore(args: dict[str, Any]) -> None:
139134
140135
141136def create_argument_parser () -> ArgumentParser :
142- logging_args = ArgumentParser (add_help = False )
143- logging_args .add_argument (
144- '-v' , '--verbose' , action = 'count' , help = 'Verbosity level, repeat for more verbosity (up to two times).'
145- )
137+ k_cli_args = KCLIArgs ()
146138
147139 definition_args = ArgumentParser (add_help = False )
148140 definition_args .add_argument ('definition_dir' , type = dir_path , help = 'Path to definition directory.' )
@@ -151,30 +143,21 @@ def create_argument_parser() -> ArgumentParser:
151143 pyk_args_command = pyk_args .add_subparsers (dest = 'command' , required = True )
152144
153145 print_args = pyk_args_command .add_parser (
154- 'print' , help = 'Pretty print a term.' , parents = [logging_args , definition_args ]
146+ 'print' ,
147+ help = 'Pretty print a term.' ,
148+ parents = [k_cli_args .logging_args , definition_args , k_cli_args .display_args ],
155149 )
156150 print_args .add_argument ('term' , type = FileType ('r' ), help = 'Input term (in JSON).' )
157- print_args .add_argument (
158- '--minimize' ,
159- dest = 'minimize' ,
160- default = True ,
161- action = 'store_true' ,
162- help = 'Minimize the JSON configuration before printing.' ,
163- )
164- print_args .add_argument (
165- '--no-minimize' ,
166- dest = 'minimize' ,
167- action = 'store_false' ,
168- help = 'Do not minimize the JSON configuration before printing.' ,
169- )
170151 print_args .add_argument ('--omit-labels' , default = '' , nargs = '?' , help = 'List of labels to omit from output.' )
171152 print_args .add_argument (
172153 '--keep-cells' , default = '' , nargs = '?' , help = 'List of cells with primitive values to keep in output.'
173154 )
174155 print_args .add_argument ('--output-file' , type = FileType ('w' ), default = '-' )
175156
176157 prove_args = pyk_args_command .add_parser (
177- 'prove' , help = 'Prove an input specification (using kprovex).' , parents = [logging_args , definition_args ]
158+ 'prove' ,
159+ help = 'Prove an input specification (using kprovex).' ,
160+ parents = [k_cli_args .logging_args , definition_args ],
178161 )
179162 prove_args .add_argument ('main_file' , type = str , help = 'Main file used for kompilation.' )
180163 prove_args .add_argument ('spec_file' , type = str , help = 'File with the specification module.' )
@@ -183,18 +166,22 @@ def create_argument_parser() -> ArgumentParser:
183166 prove_args .add_argument ('kArgs' , nargs = '*' , help = 'Arguments to pass through to K invocation.' )
184167
185168 pyk_args_command .add_parser (
186- 'graph-imports' , help = 'Graph the imports of a given definition.' , parents = [logging_args , definition_args ]
169+ 'graph-imports' ,
170+ help = 'Graph the imports of a given definition.' ,
171+ parents = [k_cli_args .logging_args , definition_args ],
187172 )
188173
189174 coverage_args = pyk_args_command .add_parser (
190- 'coverage' , help = 'Convert coverage file to human readable log.' , parents = [logging_args , definition_args ]
175+ 'coverage' ,
176+ help = 'Convert coverage file to human readable log.' ,
177+ parents = [k_cli_args .logging_args , definition_args ],
191178 )
192179 coverage_args .add_argument ('coverage_file' , type = FileType ('r' ), help = 'Coverage file to build log for.' )
193180 coverage_args .add_argument ('-o' , '--output' , type = FileType ('w' ), default = '-' )
194181
195- pyk_args_command .add_parser ('kore-to-json' , help = 'Convert textual KORE to JSON' , parents = [logging_args ])
182+ pyk_args_command .add_parser ('kore-to-json' , help = 'Convert textual KORE to JSON' , parents = [k_cli_args . logging_args ])
196183
197- pyk_args_command .add_parser ('json-to-kore' , help = 'Convert JSON to textual KORE' , parents = [logging_args ])
184+ pyk_args_command .add_parser ('json-to-kore' , help = 'Convert JSON to textual KORE' , parents = [k_cli_args . logging_args ])
198185
199186 return pyk_args
200187
0 commit comments