|
33 | 33 | # 3rd party |
34 | 34 | import click |
35 | 35 | from consolekit import click_command |
36 | | -from consolekit.options import MultiValueOption, colour_option, flag_option, verbose_option |
| 36 | +from consolekit.options import MultiValueOption, colour_option, flag_option, verbose_option, version_option |
37 | 37 | from consolekit.terminal_colours import ColourTrilean, resolve_color_default |
38 | 38 | from consolekit.tracebacks import handle_tracebacks, traceback_option |
39 | 39 | from domdf_python_tools.typing import PathLike |
40 | 40 |
|
41 | | -# this package |
42 | | -from formate import Reformatter |
43 | | -from formate.utils import _find_from_parents |
| 41 | +__all__ = ("main", "version_callback") |
44 | 42 |
|
45 | | -__all__ = ("main", ) |
| 43 | + |
| 44 | +def version_callback(ctx: click.Context, param: click.Option, value: int): |
| 45 | + # this package |
| 46 | + import formate |
| 47 | + |
| 48 | + if not value or ctx.resilient_parsing: |
| 49 | + return |
| 50 | + |
| 51 | + if value > 1: |
| 52 | + python_version = sys.version.replace('\n', ' ') |
| 53 | + click.echo(f"formate version {formate.__version__}, Python {python_version}") |
| 54 | + else: |
| 55 | + click.echo(f"formate version {formate.__version__}") |
| 56 | + |
| 57 | + ctx.exit() |
46 | 58 |
|
47 | 59 |
|
| 60 | +@version_option(version_callback) |
48 | 61 | @flag_option("--diff", "show_diff", help="Show a diff of changes made") |
49 | 62 | @traceback_option() |
50 | 63 | @colour_option() |
@@ -91,8 +104,9 @@ def main( |
91 | 104 | from domdf_python_tools.paths import PathPlus |
92 | 105 |
|
93 | 106 | # this package |
| 107 | + from formate import Reformatter |
94 | 108 | from formate.config import load_toml |
95 | | - from formate.utils import SyntaxTracebackHandler, syntaxerror_for_file |
| 109 | + from formate.utils import SyntaxTracebackHandler, _find_from_parents, syntaxerror_for_file |
96 | 110 |
|
97 | 111 | retv = 0 |
98 | 112 |
|
|
0 commit comments