Skip to content

Commit 212318c

Browse files
Merge pull request #614 from pyupio/chore/deprecation-message-for-license-command
chore/deprection message for license command
2 parents 61b2fe2 + 4149b70 commit 212318c

File tree

3 files changed

+44
-24
lines changed

3 files changed

+44
-24
lines changed

.vscode/launch.json

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
],
3333
"console": "integratedTerminal"
3434
},
35+
{
36+
"name": "Safety License",
37+
"type": "debugpy",
38+
"request": "launch",
39+
"module": "safety",
40+
"args": [
41+
"license"
42+
],
43+
"console": "integratedTerminal"
44+
},
3545
{
3646
"name": "Safety Scan --detailed-output",
3747
"type": "debugpy",

safety/cli.py

+30-23
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import absolute_import
33
import configparser
44
from dataclasses import asdict
5-
from datetime import date
5+
from datetime import date, datetime
66
from enum import Enum
77
import requests
88
import time
@@ -32,7 +32,7 @@
3232
CLI_CONFIGURE_SAVE_TO_SYSTEM, CLI_CONFIGURE_PROXY_HOST_HELP, CLI_CONFIGURE_PROXY_PORT_HELP, CLI_CONFIGURE_PROXY_PROTOCOL_HELP, \
3333
CLI_GENERATE_PATH
3434
from .cli_util import SafetyCLICommand, SafetyCLILegacyGroup, SafetyCLILegacyCommand, SafetyCLISubGroup, SafetyCLIUtilityCommand, handle_cmd_exception
35-
from safety.constants import CONFIG_FILE_USER, CONFIG_FILE_SYSTEM, EXIT_CODE_VULNERABILITIES_FOUND, EXIT_CODE_OK, EXIT_CODE_FAILURE
35+
from safety.constants import BAR_LINE, CONFIG_FILE_USER, CONFIG_FILE_SYSTEM, EXIT_CODE_VULNERABILITIES_FOUND, EXIT_CODE_OK, EXIT_CODE_FAILURE
3636
from safety.errors import InvalidCredentialError, SafetyException, SafetyError
3737
from safety.formatter import SafetyFormatter
3838
from safety.models import SafetyCLI
@@ -53,11 +53,6 @@
5353

5454
LOG = logging.getLogger(__name__)
5555

56-
DEPRECATION_DATE = date(2024, 6, 1)
57-
OLD_COMMAND = "check"
58-
NEW_COMMAND = "scan"
59-
BAR_LINE = "+===========================================================================================================================================================================================+"
60-
6156
def get_network_telemetry():
6257
import psutil
6358
import socket
@@ -240,37 +235,47 @@ def inner(ctx, *args, **kwargs):
240235

241236
return inner
242237

243-
244-
def print_deprecation_message():
238+
def print_deprecation_message(
239+
old_command: str,
240+
deprecation_date: datetime,
241+
new_command: Optional[str] = None
242+
) -> None:
245243
"""
246-
Print a formatted deprecation message for the 'check' command.
244+
Print a formatted deprecation message for a command.
247245
248246
This function uses the click library to output a visually distinct
249-
message in the console, warning users about the deprecation of the
250-
'check' command. It includes information about the deprecation date
251-
and suggests an alternative command to use.
247+
message in the console, warning users about the deprecation of a
248+
specified command. It includes information about the deprecation date
249+
and suggests an alternative command to use, if provided.
252250
253251
The message is formatted with colors and styles for emphasis:
254252
- Yellow for the border and general information
255253
- Red for the 'DEPRECATED' label
256-
- Green for the suggestion of the new command
254+
- Green for the suggestion of the new command (if provided)
257255
258-
No parameters are required, and the function doesn't return any value.
256+
Parameters:
257+
- old_command (str): The name of the deprecated command.
258+
- deprecation_date (datetime): The date when the command will no longer be supported.
259+
- new_command (str, optional): The name of the alternative command to suggest. Default is None.
259260
"""
260261
click.echo("\n")
261262
click.echo(click.style(BAR_LINE, fg="yellow", bold=True))
262263
click.echo("\n")
263264
click.echo(click.style("DEPRECATED: ", fg="red", bold=True) +
264-
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))
265-
click.echo("\n")
266-
click.echo(click.style("We highly encourage switching to the new ", fg="green") +
267-
click.style(f"`{NEW_COMMAND}`", fg="green", bold=True) +
268-
click.style(" command which is easier to use, more powerful, and can be set up to mimick check if required.", fg="green"))
265+
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))
266+
267+
if new_command:
268+
click.echo("\n")
269+
click.echo(click.style("We highly encourage switching to the new ", fg="green") +
270+
click.style(f"`{new_command}`", fg="green", bold=True) +
271+
click.style(" command which is easier to use, more powerful, and can be set up to mimic the deprecated command if required.", fg="green"))
272+
269273
click.echo("\n")
270274
click.echo(click.style(BAR_LINE, fg="yellow", bold=True))
271275
click.echo("\n")
272276

273277

278+
274279
@cli.command(cls=SafetyCLILegacyCommand, utility_command=True, help=CLI_CHECK_COMMAND_HELP)
275280
@proxy_options
276281
@auth_options(stage=False)
@@ -336,7 +341,7 @@ def check(ctx, db, full_report, stdin, files, cache, ignore, ignore_unpinned_req
336341
save_json, save_html, apply_remediations,
337342
auto_remediation_limit, no_prompt, json_version):
338343
"""
339-
[underline][DEPRECATED][/underline] `check` has been replaced by the `scan` command, and will be unsupported beyond 1 May 2024.Find vulnerabilities at a target file or enviroment.
344+
[underline][DEPRECATED][/underline] `check` has been replaced by the `scan` command, and will be unsupported beyond 1 June 2024.Find vulnerabilities at a target file or enviroment.
340345
"""
341346
LOG.info('Running check command')
342347

@@ -345,7 +350,7 @@ def check(ctx, db, full_report, stdin, files, cache, ignore, ignore_unpinned_req
345350
is_silent_output = output in silent_outputs
346351
prompt_mode = bool(not non_interactive and not stdin and not is_silent_output) and not no_prompt
347352
kwargs = {'version': json_version} if output == 'json' else {}
348-
print_deprecation_message()
353+
print_deprecation_message("check", date(2024, 6, 1), new_command="scan")
349354
try:
350355
packages = get_packages(files, stdin)
351356

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

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

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

508515

509516
@cli.command(cls=SafetyCLILegacyCommand, utility_command=True, help=CLI_GENERATE_HELP)

safety/constants.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,7 @@ def get_config_setting(name: str) -> Optional[str]:
182182
EXIT_CODE_MALFORMED_DB = 69
183183
EXIT_CODE_INVALID_PROVIDED_REPORT = 70
184184
EXIT_CODE_INVALID_REQUIREMENT = 71
185-
EXIT_CODE_EMAIL_NOT_VERIFIED = 72
185+
EXIT_CODE_EMAIL_NOT_VERIFIED = 72
186+
187+
#For Depreciated Messages
188+
BAR_LINE = "+===========================================================================================================================================================================================+"

0 commit comments

Comments
 (0)