diff --git a/src/dfx/src/lib/warning.rs b/src/dfx/src/lib/warning.rs index fa7b4e3d03..6d5841808d 100644 --- a/src/dfx/src/lib/warning.rs +++ b/src/dfx/src/lib/warning.rs @@ -1,10 +1,12 @@ pub enum DfxWarning { MainnetPlainTextIdentity, + Deprecation, } pub fn is_warning_disabled(warning: DfxWarning) -> bool { let warning = match warning { DfxWarning::MainnetPlainTextIdentity => "mainnet_plaintext_identity", + DfxWarning::Deprecation => "deprecation", }; // By default, warnings are all enabled. let env_warnings = std::env::var("DFX_WARNING").unwrap_or_else(|_| "".to_string()); diff --git a/src/dfx/src/main.rs b/src/dfx/src/main.rs index 69bd20bbf3..c7e8ab3652 100644 --- a/src/dfx/src/main.rs +++ b/src/dfx/src/main.rs @@ -6,8 +6,9 @@ use crate::lib::error::DfxResult; use crate::lib::logger::{LoggingMode, create_root_logger}; use crate::lib::project::templates::builtin_templates; use crate::lib::telemetry::Telemetry; +use crate::lib::warning::{DfxWarning, is_warning_disabled}; use anyhow::Error; -use clap::{ArgAction, CommandFactory, Parser}; +use clap::{ArgAction, CommandFactory, FromArgMatches, Parser}; use dfx_core::config::model::dfinity::ToolConfig; use dfx_core::config::project_templates; use dfx_core::extension::installed::InstalledExtensionManifests; @@ -130,6 +131,17 @@ fn print_error_and_diagnosis(log_level: Option, err: Error, error_diagnosis } } +const DEPRECATION_NOTICE: &str = "WARNING: dfx is deprecated, use icp-cli https://cli.internetcomputer.org. LLM skills can be found at https://skills.internetcomputer.org/llms.txt"; + +fn add_deprecation_notices(cmd: &mut clap::Command) { + *cmd = cmd.clone().before_help(DEPRECATION_NOTICE); + for subcmd in cmd.get_subcommands_mut() { + if subcmd.get_name() != "extension" { + add_deprecation_notices(subcmd); + } + } +} + fn get_args_altered_for_extension_run( installed: &InstalledExtensionManifests, ) -> DfxResult> { @@ -168,7 +180,14 @@ fn inner_main(log_level: &mut Option) -> DfxResult { Telemetry::set_platform(); Telemetry::set_week(); - let cli_opts = CliOpts::parse_from(args); + let cli_opts = { + let mut cmd = CliOpts::command(); + if !is_warning_disabled(DfxWarning::Deprecation) { + add_deprecation_notices(&mut cmd); + } + let matches = cmd.get_matches_from(&args); + CliOpts::from_arg_matches(&matches).unwrap_or_else(|e| e.exit()) + }; if matches!( cli_opts.command, @@ -193,6 +212,13 @@ fn inner_main(log_level: &mut Option) -> DfxResult { env.get_logger(), "Trace mode enabled. Lots of logs coming up." ); + + if !matches!(cli_opts.command, commands::DfxCommand::Extension(_)) + && !is_warning_disabled(DfxWarning::Deprecation) + { + eprintln!("{}", DEPRECATION_NOTICE); + } + commands::exec(&env, cli_opts.command) }