|
11 | 11 | from rich.theme import Theme |
12 | 12 |
|
13 | 13 | from nsls2api.cli import admin, api, auth, beamline, environment, facility, proposal |
| 14 | +from nsls2api.version import get_version |
14 | 15 |
|
15 | | -app = typer.Typer(help="NSLS-II API Command Line Interface", no_args_is_help=True) |
| 16 | +# Remove no_args_is_help and add invoke_without_command to allow a version option without subcommand. |
| 17 | +app = typer.Typer( |
| 18 | + help="NSLS-II API Command Line Interface", invoke_without_command=True |
| 19 | +) |
16 | 20 |
|
17 | 21 | # Register sub-commands |
18 | 22 | app.add_typer(admin.app, name="admin", help="Administrative commands") |
@@ -58,16 +62,11 @@ def create_command_panel(command_name: str, commands: dict) -> Panel: |
58 | 62 |
|
59 | 63 | def show_welcome(): |
60 | 64 | """Display welcome message and version information""" |
61 | | - try: |
62 | | - from nsls2api._version import version |
63 | | - |
64 | | - version_str = version |
65 | | - except ImportError: |
66 | | - version_str = "unknown" |
| 65 | + version = get_version() |
67 | 66 |
|
68 | 67 | welcome_panel = Panel( |
69 | 68 | Text("Welcome to the NSLS-II API Command Line Interface", style="info"), |
70 | | - subtitle=f"Version: {version_str}", |
| 69 | + subtitle=f"Version: {version}", |
71 | 70 | border_style="cyan", |
72 | 71 | box=box.DOUBLE, |
73 | 72 | ) |
@@ -131,15 +130,11 @@ def main( |
131 | 130 | NSLS-II API Command Line Interface |
132 | 131 | """ |
133 | 132 | if version: |
134 | | - try: |
135 | | - from nsls2api._version import version as ver |
136 | | - |
137 | | - console.print(f"[info]NSLS-II API CLI version: {ver}") |
138 | | - except ImportError: |
139 | | - console.print("[warning]Version information not available") |
| 133 | + version = get_version() |
| 134 | + console.print(f"[info]NSLS-II API CLI version: {version}") |
140 | 135 | raise typer.Exit() |
141 | 136 |
|
142 | | - # Only show welcome message and commands if no subcommand is specified |
| 137 | + # Only show a welcome message and commands if no subcommand is specified |
143 | 138 | if ctx.invoked_subcommand is None: |
144 | 139 | show_welcome() |
145 | 140 | console.print() |
|
0 commit comments