Skip to content

Commit f29a382

Browse files
authored
Make changes in CLI v3.0.0 after feedback (part 2) (#303)
1 parent 0707636 commit f29a382

31 files changed

+217
-219
lines changed

README.md

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ This guide walks you through both installation and usage.
2121
1. [Options](#options)
2222
1. [Severity Threshold](#severity-option)
2323
2. [Monitor](#monitor-option)
24-
3. [Report](#report-option)
25-
4. [Package Vulnerabilities](#package-vulnerabilities-option)
26-
5. [License Compliance](#license-compliance-option)
27-
6. [Lock Restore](#lock-restore-option)
24+
3. [Package Vulnerabilities](#package-vulnerabilities-option)
25+
4. [License Compliance](#license-compliance-option)
26+
5. [Lock Restore](#lock-restore-option)
2827
2. [Repository Scan](#repository-scan)
2928
1. [Branch Option](#branch-option)
3029
3. [Path Scan](#path-scan)
@@ -282,7 +281,7 @@ The following are the options and commands available with the Cycode CLI applica
282281
| [configure](#using-the-configure-command) | Initial command to configure your CLI client authentication. |
283282
| [ignore](#ignoring-scan-results) | Ignores a specific value, path or rule ID. |
284283
| [scan](#running-a-scan) | Scan the content for Secrets/IaC/SCA/SAST violations. You`ll need to specify which scan type to perform: commit-history/path/repository/etc. |
285-
| [report](#report-command) | Generate report. You`ll need to specify which report type to perform. |
284+
| [report](#report-command) | Generate report. You`ll need to specify which report type to perform as SBOM. |
286285
| status | Show the CLI status and exit. |
287286

288287
# Scan Command
@@ -301,7 +300,6 @@ The Cycode CLI application offers several types of scans so that you can choose
301300
| `--severity-threshold [INFO\|LOW\|MEDIUM\|HIGH\|CRITICAL]` | Show only violations at the specified level or higher. |
302301
| `--sca-scan` | Specify the SCA scan you wish to execute (`package-vulnerabilities`/`license-compliance`). The default is both. |
303302
| `--monitor` | When specified, the scan results will be recorded in the knowledge graph. Please note that when working in `monitor` mode, the knowledge graph will not be updated as a result of SCM events (Push, Repo creation). (Supported for SCA scan type only). |
304-
| `--report` | When specified, a violations report will be generated. A URL link to the report will be printed as an output to the command execution. |
305303
| `--no-restore` | When specified, Cycode will not run restore command. Will scan direct dependencies ONLY! |
306304
| `--gradle-all-sub-projects` | When specified, Cycode will run gradle restore command for all sub projects. Should run from root project directory ONLY! |
307305
| `--help` | Show options for given command. |
@@ -339,28 +337,6 @@ When using this option, the scan results from this scan will appear in the knowl
339337
> [!WARNING]
340338
> You must be an `owner` or an `admin` in Cycode to view the knowledge graph page.
341339
342-
#### Report Option
343-
344-
> [!NOTE]
345-
> This option is not available to IaC scans.
346-
347-
To push scan results tied to the [SCA policies](https://docs.cycode.com/docs/sca-policies) found in the Repository scan to Cycode, add the argument `--report` to the scan command.
348-
349-
`cycode scan -t sca --report repository ~/home/git/codebase`
350-
351-
In the same way, you can push scan results of Secrets and SAST scans to Cycode by adding the `--report` option to the scan command.
352-
353-
When using this option, the scan results from this scan will appear in the On-Demand Scans section of Cycode. To get to this page, click the link that appears after the printed results:
354-
355-
> [!WARNING]
356-
> You must be an `owner` or an `admin` in Cycode to view this page.
357-
358-
![cli-report](https://raw.githubusercontent.com/cycodehq/cycode-cli/main/images/sca_report_url.png)
359-
360-
The report page will look something like below:
361-
362-
![](https://raw.githubusercontent.com/cycodehq/cycode-cli/main/images/scan_details.png)
363-
364340
#### Package Vulnerabilities Option
365341
366342
> [!NOTE]

cycode/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from cycode.cli.consts import PROGRAM_NAME
2+
from cycode.cli.main import app
3+
4+
app(prog_name=PROGRAM_NAME)

cycode/cli/__main__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

cycode/cli/app.py

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import logging
2-
from pathlib import Path
32
from typing import Annotated, Optional
43

54
import typer
65
from typer import rich_utils
6+
from typer._completion_classes import completion_init
77
from typer.completion import install_callback, show_callback
88

99
from cycode import __version__
1010
from cycode.cli.apps import ai_remediation, auth, configure, ignore, report, scan, status
11-
from cycode.cli.cli_types import ExportTypeOption, OutputTypeOption
11+
from cycode.cli.cli_types import OutputTypeOption
1212
from cycode.cli.consts import CLI_CONTEXT_SETTINGS
1313
from cycode.cli.printers import ConsolePrinter
1414
from cycode.cli.user_settings.configuration_manager import ConfigurationManager
@@ -24,14 +24,10 @@
2424
# By default, it uses blue color which is too dark for some terminals
2525
rich_utils.RICH_HELP = "Try [cyan]'{command_path} {help_option}'[/] for help."
2626

27+
completion_init() # DO NOT TOUCH; this is required for the completion to work properly
2728

2829
_cycode_cli_docs = 'https://github.com/cycodehq/cycode-cli/blob/main/README.md'
29-
_cycode_cli_epilog = f"""[bold]Documentation[/]
30-
31-
32-
33-
For more details and advanced usage, visit: [link={_cycode_cli_docs}]{_cycode_cli_docs}[/link]
34-
"""
30+
_cycode_cli_epilog = f'[bold]Documentation:[/] [link={_cycode_cli_docs}]{_cycode_cli_docs}[/link]'
3531

3632
app = typer.Typer(
3733
pretty_exceptions_show_locals=False,
@@ -64,13 +60,14 @@ def check_latest_version_on_close(ctx: typer.Context) -> None:
6460

6561

6662
def export_if_needed_on_close(ctx: typer.Context) -> None:
63+
scan_finalized = ctx.obj.get('scan_finalized')
6764
printer = ctx.obj.get('console_printer')
68-
if printer.is_recording:
65+
if scan_finalized and printer.is_recording:
6966
printer.export()
7067

7168

69+
_AUTH_RICH_HELP_PANEL = 'Authentication options'
7270
_COMPLETION_RICH_HELP_PANEL = 'Completion options'
73-
_EXPORT_RICH_HELP_PANEL = 'Export options'
7471

7572

7673
@app.callback()
@@ -90,25 +87,18 @@ def app_callback(
9087
Optional[str],
9188
typer.Option(hidden=True, help='Characteristic JSON object that lets servers identify the application.'),
9289
] = None,
93-
export_type: Annotated[
94-
ExportTypeOption,
90+
client_secret: Annotated[
91+
Optional[str],
9592
typer.Option(
96-
'--export-type',
97-
case_sensitive=False,
98-
help='Specify the export type. '
99-
'HTML and SVG will export terminal output and rely on --output option. '
100-
'JSON always exports JSON.',
101-
rich_help_panel=_EXPORT_RICH_HELP_PANEL,
93+
help='Specify a Cycode client secret for this specific scan execution.',
94+
rich_help_panel=_AUTH_RICH_HELP_PANEL,
10295
),
103-
] = ExportTypeOption.JSON,
104-
export_file: Annotated[
105-
Optional[Path],
96+
] = None,
97+
client_id: Annotated[
98+
Optional[str],
10699
typer.Option(
107-
'--export-file',
108-
help='Export file. Path to the file where the export will be saved. ',
109-
dir_okay=False,
110-
writable=True,
111-
rich_help_panel=_EXPORT_RICH_HELP_PANEL,
100+
help='Specify a Cycode client ID for this specific scan execution.',
101+
rich_help_panel=_AUTH_RICH_HELP_PANEL,
112102
),
113103
] = None,
114104
_: Annotated[
@@ -150,10 +140,11 @@ def app_callback(
150140
if output == OutputTypeOption.JSON:
151141
no_progress_meter = True
152142

143+
ctx.obj['client_id'] = client_id
144+
ctx.obj['client_secret'] = client_secret
145+
153146
ctx.obj['progress_bar'] = get_progress_bar(hidden=no_progress_meter, sections=SCAN_PROGRESS_BAR_SECTIONS)
154147

155-
ctx.obj['export_type'] = export_type
156-
ctx.obj['export_file'] = export_file
157148
ctx.obj['console_printer'] = ConsolePrinter(ctx)
158149
ctx.call_on_close(lambda: export_if_needed_on_close(ctx))
159150

cycode/cli/apps/ai_remediation/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
app = typer.Typer()
66

7-
_ai_remediation_epilog = """
8-
Note: AI remediation suggestions are generated automatically and should be reviewed before applying.
9-
"""
7+
_ai_remediation_epilog = (
8+
'Note: AI remediation suggestions are generated automatically and should be reviewed before applying.'
9+
)
1010

1111
app.command(
1212
name='ai-remediation',

cycode/cli/apps/ai_remediation/ai_remediation_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def ai_remediation_command(
2424
* `cycode ai-remediation <detection_id>`: View remediation guidance
2525
* `cycode ai-remediation <detection_id> --fix`: Apply suggested fixes
2626
"""
27-
client = get_scan_cycode_client()
27+
client = get_scan_cycode_client(ctx)
2828

2929
try:
3030
remediation_markdown = client.get_ai_remediation(detection_id)

cycode/cli/apps/auth/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
from cycode.cli.apps.auth.auth_command import auth_command
44

55
_auth_command_docs = 'https://github.com/cycodehq/cycode-cli/blob/main/README.md#using-the-auth-command'
6-
_auth_command_epilog = f"""[bold]Documentation[/]
7-
8-
9-
10-
For more details and advanced usage, visit: [link={_auth_command_docs}]{_auth_command_docs}[/link]
11-
"""
6+
_auth_command_epilog = f'[bold]Documentation:[/] [link={_auth_command_docs}]{_auth_command_docs}[/link]'
127

138
app = typer.Typer(no_args_is_help=False)
149
app.command(name='auth', epilog=_auth_command_epilog, short_help='Authenticate your machine with Cycode.')(auth_command)

cycode/cli/apps/auth/auth_common.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
def get_authorization_info(ctx: 'Context') -> Optional[AuthInfo]:
1414
printer = ctx.obj.get('console_printer')
1515

16-
client_id, client_secret = CredentialsManager().get_credentials()
16+
client_id, client_secret = ctx.obj.get('client_id'), ctx.obj.get('client_secret')
17+
if not client_id or not client_secret:
18+
client_id, client_secret = CredentialsManager().get_credentials()
19+
1720
if not client_id or not client_secret:
1821
return None
1922

cycode/cli/apps/configure/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
from cycode.cli.apps.configure.configure_command import configure_command
44

55
_configure_command_docs = 'https://github.com/cycodehq/cycode-cli/blob/main/README.md#using-the-configure-command'
6-
_configure_command_epilog = f"""[bold]Documentation[/]
7-
8-
9-
10-
For more details and advanced usage, visit: [link={_configure_command_docs}]{_configure_command_docs}[/link]
11-
"""
6+
_configure_command_epilog = f'[bold]Documentation:[/] [link={_configure_command_docs}]{_configure_command_docs}[/link]'
127

138

149
app = typer.Typer(no_args_is_help=True)

cycode/cli/apps/report/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
from cycode.cli.apps.report.report_command import report_command
55

66
app = typer.Typer(name='report', no_args_is_help=True)
7-
app.callback(short_help='Generate report. You`ll need to specify which report type to perform.')(report_command)
7+
app.callback(short_help='Generate report. You`ll need to specify which report type to perform as SBOM.')(report_command)
88
app.add_typer(sbom.app)

0 commit comments

Comments
 (0)