Skip to content

Commit

Permalink
CM-29960 - Migrate all CLI commands to new project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshalX committed Dec 6, 2023
1 parent 91d3ea5 commit 1e12009
Show file tree
Hide file tree
Showing 40 changed files with 705 additions and 622 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import click

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


@authenticate.command(
@auth_command.command(
name='check', short_help='Checks that your machine is associating the CLI with your Cycode account.'
)
@click.pass_context
Expand Down
File renamed without changes.
79 changes: 79 additions & 0 deletions cycode/cli/commands/main_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import logging
from typing import Optional

import click

from cycode.cli.commands.auth.auth_command import auth_command
from cycode.cli.commands.configure.configure_command import configure_command
from cycode.cli.commands.ignore.ignore_command import ignore_command
from cycode.cli.commands.report.report_command import report_command
from cycode.cli.commands.scan.scan_command import scan_command
from cycode.cli.commands.version.version_command import version_command
from cycode.cli.consts import (
CLI_CONTEXT_SETTINGS,
)
from cycode.cli.user_settings.configuration_manager import ConfigurationManager
from cycode.cli.utils.progress_bar import SCAN_PROGRESS_BAR_SECTIONS, get_progress_bar
from cycode.cyclient.config import set_logging_level
from cycode.cyclient.cycode_client_base import CycodeClientBase
from cycode.cyclient.models import UserAgentOptionScheme


@click.group(
commands={
'scan': scan_command,
'report': report_command,
'configure': configure_command,
'ignore': ignore_command,
'auth': auth_command,
'version': version_command,
},
context_settings=CLI_CONTEXT_SETTINGS,
)
@click.option(
'--verbose',
'-v',
is_flag=True,
default=False,
help='Show detailed logs.',
)
@click.option(
'--no-progress-meter',
is_flag=True,
default=False,
help='Do not show the progress meter.',
)
@click.option(
'--output',
'-o',
default='text',
help='Specify the output type (the default is text).',
type=click.Choice(['text', 'json', 'table']),
)
@click.option(
'--user-agent',
default=None,
help='Characteristic JSON object that lets servers identify the application.',
type=str,
)
@click.pass_context
def main_cli(
context: click.Context, verbose: bool, no_progress_meter: bool, output: str, user_agent: Optional[str]
) -> None:
context.ensure_object(dict)
configuration_manager = ConfigurationManager()

verbose = verbose or configuration_manager.get_verbose_flag()
context.obj['verbose'] = verbose
if verbose:
set_logging_level(logging.DEBUG)

context.obj['output'] = output
if output == 'json':
no_progress_meter = True

context.obj['progress_bar'] = get_progress_bar(hidden=no_progress_meter, sections=SCAN_PROGRESS_BAR_SECTIONS)

if user_agent:
user_agent_option = UserAgentOptionScheme().loads(user_agent)
CycodeClientBase.enrich_user_agent(user_agent_option.user_agent_suffix)
2 changes: 1 addition & 1 deletion cycode/cli/commands/report/sbom/sbom_path_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from cycode.cli import consts
from cycode.cli.commands.report.sbom.common import create_sbom_report, send_report_feedback
from cycode.cli.commands.report.sbom.handle_errors import handle_report_exception
from cycode.cli.exceptions.handle_report_sbom_errors import handle_report_exception
from cycode.cli.files_collector.path_documents import get_relevant_document
from cycode.cli.files_collector.sca.sca_code_scanner import perform_pre_scan_documents_actions
from cycode.cli.files_collector.zip_documents import zip_documents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import click

from cycode.cli.commands.report.sbom.common import create_sbom_report, send_report_feedback
from cycode.cli.commands.report.sbom.handle_errors import handle_report_exception
from cycode.cli.exceptions.handle_report_sbom_errors import handle_report_exception
from cycode.cli.utils.get_api_client import get_report_cycode_client
from cycode.cli.utils.progress_bar import SbomReportProgressBarSection

Expand Down
Empty file.
Loading

0 comments on commit 1e12009

Please sign in to comment.