Skip to content

Commit

Permalink
chore/deprection-message-for-license-command
Browse files Browse the repository at this point in the history
  • Loading branch information
SafetyQuincyF committed Oct 22, 2024
1 parent c2d613d commit c07afc5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
],
"console": "integratedTerminal"
},
{
"name": "Safety License",
"type": "debugpy",
"request": "launch",
"module": "safety",
"args": [
"license"
],
"console": "integratedTerminal"
},
{
"name": "Safety Scan --detailed-output",
"type": "debugpy",
Expand Down
51 changes: 29 additions & 22 deletions safety/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import absolute_import
import configparser
from dataclasses import asdict
from datetime import date
from datetime import date, datetime
from enum import Enum
import requests
import time
Expand Down Expand Up @@ -32,7 +32,7 @@
CLI_CONFIGURE_SAVE_TO_SYSTEM, CLI_CONFIGURE_PROXY_HOST_HELP, CLI_CONFIGURE_PROXY_PORT_HELP, CLI_CONFIGURE_PROXY_PROTOCOL_HELP, \
CLI_GENERATE_PATH
from .cli_util import SafetyCLICommand, SafetyCLILegacyGroup, SafetyCLILegacyCommand, SafetyCLISubGroup, SafetyCLIUtilityCommand, handle_cmd_exception
from safety.constants import CONFIG_FILE_USER, CONFIG_FILE_SYSTEM, EXIT_CODE_VULNERABILITIES_FOUND, EXIT_CODE_OK, EXIT_CODE_FAILURE
from safety.constants import BAR_LINE, CONFIG_FILE_USER, CONFIG_FILE_SYSTEM, EXIT_CODE_VULNERABILITIES_FOUND, EXIT_CODE_OK, EXIT_CODE_FAILURE
from safety.errors import InvalidCredentialError, SafetyException, SafetyError
from safety.formatter import SafetyFormatter
from safety.models import SafetyCLI
Expand All @@ -53,11 +53,6 @@

LOG = logging.getLogger(__name__)

DEPRECATION_DATE = date(2024, 6, 1)
OLD_COMMAND = "check"
NEW_COMMAND = "scan"
BAR_LINE = "+===========================================================================================================================================================================================+"

def get_network_telemetry():
import psutil
import socket
Expand Down Expand Up @@ -240,37 +235,47 @@ def inner(ctx, *args, **kwargs):

return inner


def print_deprecation_message():
def print_deprecation_message(
old_command: str,
deprecation_date: datetime,
new_command: Optional[str] = None
) -> None:
"""
Print a formatted deprecation message for the 'check' command.
Print a formatted deprecation message for a command.
This function uses the click library to output a visually distinct
message in the console, warning users about the deprecation of the
'check' command. It includes information about the deprecation date
and suggests an alternative command to use.
message in the console, warning users about the deprecation of a
specified command. It includes information about the deprecation date
and suggests an alternative command to use, if provided.
The message is formatted with colors and styles for emphasis:
- Yellow for the border and general information
- Red for the 'DEPRECATED' label
- Green for the suggestion of the new command
- Green for the suggestion of the new command (if provided)
No parameters are required, and the function doesn't return any value.
Parameters:
- old_command (str): The name of the deprecated command.
- deprecation_date (datetime): The date when the command will no longer be supported.
- new_command (str, optional): The name of the alternative command to suggest. Default is None.
"""
click.echo("\n")
click.echo(click.style(BAR_LINE, fg="yellow", bold=True))
click.echo("\n")
click.echo(click.style("DEPRECATED: ", fg="red", bold=True) +
click.style(f"this command (`{OLD_COMMAND}`) has been DEPRECATED, and will be unsupported beyond {DEPRECATION_DATE.strftime('%d %B %Y')}.", fg="yellow", bold=True))
click.echo("\n")
click.echo(click.style("We highly encourage switching to the new ", fg="green") +
click.style(f"`{NEW_COMMAND}`", fg="green", bold=True) +
click.style(" command which is easier to use, more powerful, and can be set up to mimick check if required.", fg="green"))
click.style(f"this command (`{old_command}`) has been DEPRECATED, and will be unsupported beyond {deprecation_date.strftime('%d %B %Y')}.", fg="yellow", bold=True))

if new_command:
click.echo("\n")
click.echo(click.style("We highly encourage switching to the new ", fg="green") +
click.style(f"`{new_command}`", fg="green", bold=True) +
click.style(" command which is easier to use, more powerful, and can be set up to mimic the deprecated command if required.", fg="green"))

click.echo("\n")
click.echo(click.style(BAR_LINE, fg="yellow", bold=True))
click.echo("\n")



@cli.command(cls=SafetyCLILegacyCommand, utility_command=True, help=CLI_CHECK_COMMAND_HELP)
@proxy_options
@auth_options(stage=False)
Expand Down Expand Up @@ -345,7 +350,7 @@ def check(ctx, db, full_report, stdin, files, cache, ignore, ignore_unpinned_req
is_silent_output = output in silent_outputs
prompt_mode = bool(not non_interactive and not stdin and not is_silent_output) and not no_prompt
kwargs = {'version': json_version} if output == 'json' else {}
print_deprecation_message()
print_deprecation_message("check", date(2024, 6, 1), new_command="scan")
try:
packages = get_packages(files, stdin)

Expand Down Expand Up @@ -427,7 +432,7 @@ def check(ctx, db, full_report, stdin, files, cache, ignore, ignore_unpinned_req
announcements, vulns, remediations, full_report, packages, fixes)

safety.save_report(save_html, 'safety-report.html', html_report)
print_deprecation_message()
print_deprecation_message("check", date(2024, 6, 1), new_command="scan")
if exit_code and found_vulns:
LOG.info('Exiting with default code for vulnerabilities found')
sys.exit(EXIT_CODE_VULNERABILITIES_FOUND)
Expand Down Expand Up @@ -478,6 +483,7 @@ def license(ctx, db, output, cache, files):
"""
Find the open source licenses used by your Python dependencies.
"""
print_deprecation_message("license", date(2024, 6, 1), new_command=None)
LOG.info('Running license command')
packages = get_packages(files, False)
licenses_db = {}
Expand All @@ -504,6 +510,7 @@ def license(ctx, db, output, cache, files):
output_report = SafetyFormatter(output=output).render_licenses(announcements, filtered_packages_licenses)

click.secho(output_report, nl=True)
print_deprecation_message("license", date(2024, 6, 1), new_command=None)


@cli.command(cls=SafetyCLILegacyCommand, utility_command=True, help=CLI_GENERATE_HELP)
Expand Down
5 changes: 4 additions & 1 deletion safety/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,7 @@ def get_config_setting(name: str) -> Optional[str]:
EXIT_CODE_MALFORMED_DB = 69
EXIT_CODE_INVALID_PROVIDED_REPORT = 70
EXIT_CODE_INVALID_REQUIREMENT = 71
EXIT_CODE_EMAIL_NOT_VERIFIED = 72
EXIT_CODE_EMAIL_NOT_VERIFIED = 72

#For Depreciated Messages
BAR_LINE = "+===========================================================================================================================================================================================+"

0 comments on commit c07afc5

Please sign in to comment.