Skip to content

Commit 16bc696

Browse files
authored
CM-29960 - Migrate all CLI commands to new project structure (#182)
1 parent 91d3ea5 commit 16bc696

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+711
-628
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import click
44

5-
from cycode.cli.auth.auth_manager import AuthManager
5+
from cycode.cli.commands.auth.auth_manager import AuthManager
66
from cycode.cli.exceptions.custom_exceptions import AuthProcessError, HttpUnauthorizedError, NetworkError
77
from cycode.cli.models import CliError, CliErrors, CliResult
88
from cycode.cli.printers import ConsolePrinter
@@ -15,7 +15,7 @@
1515
invoke_without_command=True, short_help='Authenticate your machine to associate the CLI with your Cycode account.'
1616
)
1717
@click.pass_context
18-
def authenticate(context: click.Context) -> None:
18+
def auth_command(context: click.Context) -> None:
1919
"""Authenticates your machine."""
2020
if context.invoked_subcommand is not None:
2121
# if it is a subcommand, do nothing
@@ -33,7 +33,7 @@ def authenticate(context: click.Context) -> None:
3333
_handle_exception(context, e)
3434

3535

36-
@authenticate.command(
36+
@auth_command.command(
3737
name='check', short_help='Checks that your machine is associating the CLI with your Cycode account.'
3838
)
3939
@click.pass_context

cycode/cli/commands/main_cli.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import logging
2+
from typing import Optional
3+
4+
import click
5+
6+
from cycode.cli.commands.auth.auth_command import auth_command
7+
from cycode.cli.commands.configure.configure_command import configure_command
8+
from cycode.cli.commands.ignore.ignore_command import ignore_command
9+
from cycode.cli.commands.report.report_command import report_command
10+
from cycode.cli.commands.scan.scan_command import scan_command
11+
from cycode.cli.commands.version.version_command import version_command
12+
from cycode.cli.consts import (
13+
CLI_CONTEXT_SETTINGS,
14+
)
15+
from cycode.cli.user_settings.configuration_manager import ConfigurationManager
16+
from cycode.cli.utils.progress_bar import SCAN_PROGRESS_BAR_SECTIONS, get_progress_bar
17+
from cycode.cyclient.config import set_logging_level
18+
from cycode.cyclient.cycode_client_base import CycodeClientBase
19+
from cycode.cyclient.models import UserAgentOptionScheme
20+
21+
22+
@click.group(
23+
commands={
24+
'scan': scan_command,
25+
'report': report_command,
26+
'configure': configure_command,
27+
'ignore': ignore_command,
28+
'auth': auth_command,
29+
'version': version_command,
30+
},
31+
context_settings=CLI_CONTEXT_SETTINGS,
32+
)
33+
@click.option(
34+
'--verbose',
35+
'-v',
36+
is_flag=True,
37+
default=False,
38+
help='Show detailed logs.',
39+
)
40+
@click.option(
41+
'--no-progress-meter',
42+
is_flag=True,
43+
default=False,
44+
help='Do not show the progress meter.',
45+
)
46+
@click.option(
47+
'--output',
48+
'-o',
49+
default='text',
50+
help='Specify the output type (the default is text).',
51+
type=click.Choice(['text', 'json', 'table']),
52+
)
53+
@click.option(
54+
'--user-agent',
55+
default=None,
56+
help='Characteristic JSON object that lets servers identify the application.',
57+
type=str,
58+
)
59+
@click.pass_context
60+
def main_cli(
61+
context: click.Context, verbose: bool, no_progress_meter: bool, output: str, user_agent: Optional[str]
62+
) -> None:
63+
context.ensure_object(dict)
64+
configuration_manager = ConfigurationManager()
65+
66+
verbose = verbose or configuration_manager.get_verbose_flag()
67+
context.obj['verbose'] = verbose
68+
if verbose:
69+
set_logging_level(logging.DEBUG)
70+
71+
context.obj['output'] = output
72+
if output == 'json':
73+
no_progress_meter = True
74+
75+
context.obj['progress_bar'] = get_progress_bar(hidden=no_progress_meter, sections=SCAN_PROGRESS_BAR_SECTIONS)
76+
77+
if user_agent:
78+
user_agent_option = UserAgentOptionScheme().loads(user_agent)
79+
CycodeClientBase.enrich_user_agent(user_agent_option.user_agent_suffix)

cycode/cli/commands/report/sbom/path/__init__.py

Whitespace-only changes.

cycode/cli/commands/report/sbom/sbom_path_command.py renamed to cycode/cli/commands/report/sbom/path/path_command.py

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

55
from cycode.cli import consts
66
from cycode.cli.commands.report.sbom.common import create_sbom_report, send_report_feedback
7-
from cycode.cli.commands.report.sbom.handle_errors import handle_report_exception
7+
from cycode.cli.exceptions.handle_report_sbom_errors import handle_report_exception
88
from cycode.cli.files_collector.path_documents import get_relevant_document
99
from cycode.cli.files_collector.sca.sca_code_scanner import perform_pre_scan_documents_actions
1010
from cycode.cli.files_collector.zip_documents import zip_documents
@@ -15,7 +15,7 @@
1515
@click.command(short_help='Generate SBOM report for provided path in the command.')
1616
@click.argument('path', nargs=1, type=click.Path(exists=True, resolve_path=True), required=True)
1717
@click.pass_context
18-
def sbom_path_command(context: click.Context, path: str) -> None:
18+
def path_command(context: click.Context, path: str) -> None:
1919
client = get_report_cycode_client()
2020
report_parameters = context.obj['report_parameters']
2121
output_format = report_parameters.output_format

cycode/cli/commands/report/sbom/repository_url/__init__.py

Whitespace-only changes.

cycode/cli/commands/report/sbom/sbom_repository_url_command.py renamed to cycode/cli/commands/report/sbom/repository_url/repository_url_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import click
44

55
from cycode.cli.commands.report.sbom.common import create_sbom_report, send_report_feedback
6-
from cycode.cli.commands.report.sbom.handle_errors import handle_report_exception
6+
from cycode.cli.exceptions.handle_report_sbom_errors import handle_report_exception
77
from cycode.cli.utils.get_api_client import get_report_cycode_client
88
from cycode.cli.utils.progress_bar import SbomReportProgressBarSection
99

1010

1111
@click.command(short_help='Generate SBOM report for provided repository URI in the command.')
1212
@click.argument('uri', nargs=1, type=str, required=True)
1313
@click.pass_context
14-
def sbom_repository_url_command(context: click.Context, uri: str) -> None:
14+
def repository_url_command(context: click.Context, uri: str) -> None:
1515
progress_bar = context.obj['progress_bar']
1616
progress_bar.start()
1717
progress_bar.set_section_length(SbomReportProgressBarSection.PREPARE_LOCAL_FILES)

cycode/cli/commands/report/sbom/sbom_command.py

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

44
import click
55

6-
from cycode.cli.commands.report.sbom.sbom_path_command import sbom_path_command
7-
from cycode.cli.commands.report.sbom.sbom_repository_url_command import sbom_repository_url_command
6+
from cycode.cli.commands.report.sbom.path.path_command import path_command
7+
from cycode.cli.commands.report.sbom.repository_url.repository_url_command import repository_url_command
88
from cycode.cli.config import config
99
from cycode.cyclient.report_client import ReportParameters
1010

1111

1212
@click.group(
1313
commands={
14-
'path': sbom_path_command,
15-
'repository_url': sbom_repository_url_command,
14+
'path': path_command,
15+
'repository_url': repository_url_command,
1616
},
1717
short_help='Generate SBOM report for remote repository by url or local directory by path.',
1818
)

0 commit comments

Comments
 (0)