Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/dfx/src/lib/warning.rs
Original file line number Diff line number Diff line change
@@ -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());
Expand Down
30 changes: 28 additions & 2 deletions src/dfx/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
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;
Expand Down Expand Up @@ -130,6 +131,17 @@
}
}

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<Vec<OsString>> {
Expand Down Expand Up @@ -168,7 +180,14 @@
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,
Expand All @@ -193,6 +212,13 @@
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);

Check failure on line 219 in src/dfx/src/main.rs

View workflow job for this annotation

GitHub Actions / lint (macos-15)

variables can be used directly in the `format!` string

Check failure on line 219 in src/dfx/src/main.rs

View workflow job for this annotation

GitHub Actions / lint (ubuntu-24.04)

variables can be used directly in the `format!` string

Check failure on line 219 in src/dfx/src/main.rs

View workflow job for this annotation

GitHub Actions / lint (ubuntu-24.04-arm)

variables can be used directly in the `format!` string
}

commands::exec(&env, cli_opts.command)
}

Expand Down
Loading