|
| 1 | +import json |
1 | 2 | import logging |
2 | 3 | import sys |
3 | 4 | from typing import TYPE_CHECKING, List, Optional, Tuple |
|
8 | 9 | from cycode.cli import code_scanner |
9 | 10 | from cycode.cli.auth.auth_command import authenticate |
10 | 11 | from cycode.cli.config import config |
11 | | -from cycode.cli.consts import ISSUE_DETECTED_STATUS_CODE, NO_ISSUES_STATUS_CODE |
| 12 | +from cycode.cli.consts import ISSUE_DETECTED_STATUS_CODE, NO_ISSUES_STATUS_CODE, PROGRAM_NAME |
12 | 13 | from cycode.cli.models import Severity |
13 | 14 | from cycode.cli.user_settings.configuration_manager import ConfigurationManager |
14 | 15 | from cycode.cli.user_settings.credentials_manager import CredentialsManager |
@@ -180,8 +181,30 @@ def finalize(context: click.Context, *_, **__) -> None: |
180 | 181 | sys.exit(exit_code) |
181 | 182 |
|
182 | 183 |
|
| 184 | +@click.command(short_help='Show the version and exit') |
| 185 | +@click.pass_context |
| 186 | +def version(context: click.Context) -> None: |
| 187 | + output = context.obj['output'] |
| 188 | + |
| 189 | + prog = PROGRAM_NAME |
| 190 | + ver = __version__ |
| 191 | + |
| 192 | + message = f'{prog}, version {ver}' |
| 193 | + if output == 'json': |
| 194 | + message = json.dumps({'name': prog, 'version': ver}) |
| 195 | + |
| 196 | + click.echo(message, color=context.color) |
| 197 | + context.exit() |
| 198 | + |
| 199 | + |
183 | 200 | @click.group( |
184 | | - commands={'scan': code_scan, 'configure': set_credentials, 'ignore': add_exclusions, 'auth': authenticate}, |
| 201 | + commands={ |
| 202 | + 'scan': code_scan, |
| 203 | + 'configure': set_credentials, |
| 204 | + 'ignore': add_exclusions, |
| 205 | + 'auth': authenticate, |
| 206 | + 'version': version, |
| 207 | + }, |
185 | 208 | context_settings=CONTEXT, |
186 | 209 | ) |
187 | 210 | @click.option( |
@@ -210,7 +233,7 @@ def finalize(context: click.Context, *_, **__) -> None: |
210 | 233 | help='Characteristic JSON object that lets servers identify the application', |
211 | 234 | type=str, |
212 | 235 | ) |
213 | | -@click.version_option(__version__, prog_name='cycode') |
| 236 | +@click.version_option(__version__, prog_name=PROGRAM_NAME) |
214 | 237 | @click.pass_context |
215 | 238 | def main_cli( |
216 | 239 | context: click.Context, verbose: bool, no_progress_meter: bool, output: str, user_agent: Optional[str] |
|
0 commit comments