|
1 | | -""" main module of testsdiffer for console (cli) usage""" |
2 | | -import os |
| 1 | +""" main module of testsdiffer for console (cli) usage""" |
| 2 | + |
3 | 3 | import pprint |
| 4 | +import sys |
4 | 5 |
|
5 | | -import clifier |
| 6 | +import click |
6 | 7 |
|
7 | 8 | from codegraph import __version__, core |
8 | 9 |
|
9 | | -CLI_CFG_NAME = "conf/cli.yml" |
10 | | - |
11 | | - |
12 | | -def cli(): |
13 | | - config_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), CLI_CFG_NAME) |
14 | | - _cli = clifier.Clifier(config_path, prog_version=__version__) |
15 | | - parser = _cli.create_parser() |
16 | | - args = parser.parse_args() |
| 10 | +CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"]) |
| 11 | + |
| 12 | + |
| 13 | +@click.command(context_settings=CONTEXT_SETTINGS) |
| 14 | +@click.version_option(version=__version__, message="CodeGraph version %(version)s") |
| 15 | +@click.argument("paths", nargs=-1, type=click.Path(exists=True)) |
| 16 | +@click.option( |
| 17 | + "-o", |
| 18 | + "--object-only", |
| 19 | + is_flag=True, |
| 20 | + help="Don't visualize code dependencies as graph", |
| 21 | +) |
| 22 | +def cli(paths, object_only): |
| 23 | + """ |
| 24 | + Tool that creates a graph of code to show dependencies between code entities (methods, classes, etc.). |
| 25 | + CodeGraph does not execute code, it is based only on lex and syntax parsing. |
| 26 | +
|
| 27 | + PATHS: Provide path(s) to code base |
| 28 | + """ |
| 29 | + if not paths: |
| 30 | + click.echo( |
| 31 | + "Error: No paths provided. Please specify at least one path to the code base.", |
| 32 | + err=True, |
| 33 | + ) |
| 34 | + sys.exit(1) |
| 35 | + |
| 36 | + args = {"paths": paths, "object_only": object_only} |
17 | 37 | main(args) |
18 | 38 |
|
19 | 39 |
|
20 | 40 | def main(args): |
21 | 41 | usage_graph = core.CodeGraph(args).usage_graph() |
22 | 42 | pprint.pprint(usage_graph) |
23 | | - if not args.object_only: |
| 43 | + if not args["object_only"]: |
24 | 44 | # to make more quick work if not needed to visualize |
25 | 45 | import codegraph.vizualyzer as vz |
26 | 46 |
|
27 | 47 | vz.draw_graph(usage_graph) |
| 48 | + |
| 49 | + |
| 50 | +if __name__ == "__main__": |
| 51 | + cli() |
0 commit comments