Rename misused "deprecation" to removal (#10000)

# Description
In the past we named the process of completely removing a command and
providing a basic error message pointing to the new alternative
"deprecation".

But this doesn't match the expectation of most users that have seen
deprecation _warnings_ that alert to either impending removal or
discouraged use after a stability promise.

# User-Facing Changes
Command category changed from `deprecated` to `removed`
This commit is contained in:
Stefan Holderbach 2023-08-14 21:17:31 +02:00 committed by GitHub
parent 0a5f41abc2
commit 435348aa61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 33 additions and 51 deletions

View file

@ -374,7 +374,7 @@ pub fn add_shell_command_context(mut engine_state: EngineState) -> EngineState {
IsAdmin,
};
// Deprecated
// Removed
bind_command! {
LetEnv,
DateFormat,

View file

@ -3,7 +3,6 @@ mod conversions;
mod date;
mod debug;
mod default_context;
mod deprecated;
mod env;
mod example_test;
mod experimental;
@ -21,6 +20,7 @@ mod path;
mod platform;
mod progress_bar;
mod random;
mod removed;
mod shells;
mod sort_utils;
mod strings;
@ -32,7 +32,6 @@ pub use conversions::*;
pub use date::*;
pub use debug::*;
pub use default_context::*;
pub use deprecated::*;
pub use env::*;
#[cfg(test)]
pub use example_test::test_examples;
@ -50,6 +49,7 @@ pub use network::*;
pub use path::*;
pub use platform::*;
pub use random::*;
pub use removed::*;
pub use shells::*;
pub use sort_utils::*;
pub use strings::*;

View file

@ -23,15 +23,11 @@ impl Command for SubCommand {
SyntaxShape::String,
"the desired date format",
)
.category(Category::Date)
.category(Category::Removed)
}
fn usage(&self) -> &str {
"Format a given date using a format string."
}
fn search_terms(&self) -> Vec<&str> {
vec!["fmt", "strftime"]
"Removed command: use `format date` instead"
}
fn run(
@ -41,7 +37,7 @@ impl Command for SubCommand {
call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
Err(nu_protocol::ShellError::DeprecatedCommand(
Err(nu_protocol::ShellError::RemovedCommand(
self.name().to_string(),
"format date".to_owned(),
call.head,

View file

@ -20,11 +20,11 @@ impl Command for LetEnv {
SyntaxShape::Keyword(b"=".to_vec(), Box::new(SyntaxShape::MathExpression)),
"equals sign followed by value",
)
.category(Category::Deprecated)
.category(Category::Removed)
}
fn usage(&self) -> &str {
"`let-env FOO = ...` is deprecated, use `$env.FOO = ...` instead."
"`let-env FOO = ...` has been removed, use `$env.FOO = ...` instead."
}
fn run(
@ -34,7 +34,7 @@ impl Command for LetEnv {
call: &Call,
_: PipelineData,
) -> Result<PipelineData, ShellError> {
Err(nu_protocol::ShellError::DeprecatedCommand(
Err(nu_protocol::ShellError::RemovedCommand(
self.name().to_string(),
"$env.<environment variable> = ...".to_owned(),
call.head,

View file

@ -1,7 +1,7 @@
mod deprecated_commands;
mod format;
mod let_env;
mod removed_commands;
pub use deprecated_commands::*;
pub use format::SubCommand as DateFormat;
pub use let_env::LetEnv;
pub use removed_commands::*;

View file

@ -1,10 +1,10 @@
use std::collections::HashMap;
/// Return map of <deprecated_command_name, new_command_name>
/// This covers simple deprecated commands nicely, but it's not great for deprecating
/// Return map of <removed_command_name, new_command_name>
/// This covers simple removed commands nicely, but it's not great for deprecating
/// subcommands like `foo bar` where `foo` is still a valid command.
/// For those, it's currently easiest to have a "stub" command that just returns an error.
pub fn deprecated_commands() -> HashMap<String, String> {
pub fn removed_commands() -> HashMap<String, String> {
[
("fetch".to_string(), "http get".to_string()),
("post".to_string(), "http post".to_string()),

View file

@ -295,15 +295,15 @@ impl ExternalCommand {
match err.kind() {
// If file not found, try suggesting alternative commands to the user
std::io::ErrorKind::NotFound => {
// recommend a replacement if the user tried a deprecated command
// recommend a replacement if the user tried a removed command
let command_name_lower = self.name.item.to_lowercase();
let deprecated = crate::deprecated_commands();
if deprecated.contains_key(&command_name_lower) {
let replacement = match deprecated.get(&command_name_lower) {
let removed_from_nu = crate::removed_commands();
if removed_from_nu.contains_key(&command_name_lower) {
let replacement = match removed_from_nu.get(&command_name_lower) {
Some(s) => s.clone(),
None => "".to_string(),
};
return Err(ShellError::DeprecatedCommand(
return Err(ShellError::RemovedCommand(
command_name_lower,
replacement,
self.name.span,

View file

@ -65,8 +65,8 @@ fn commands_declare_input_output_types() {
let sig_name = cmd.signature().name;
let category = cmd.signature().category;
if matches!(category, Category::Deprecated | Category::Custom(_)) {
// Deprecated commands don't have to conform
if matches!(category, Category::Removed | Category::Custom(_)) {
// Deprecated/Removed commands don't have to conform
// TODO: also upgrade the `--features dataframe` commands
continue;
}

View file

@ -1,7 +1,7 @@
use nu_protocol::{
ast::Call,
engine::{EngineState, Stack},
Example, IntoPipelineData, PipelineData, Signature, Span, SyntaxShape, Value,
Category, Example, IntoPipelineData, PipelineData, Signature, Span, SyntaxShape, Value,
};
use std::{collections::HashMap, fmt::Write};
@ -94,8 +94,8 @@ fn get_documentation(
let signatures = engine_state.get_signatures(true);
for sig in signatures {
if sig.name.starts_with(&format!("{cmd_name} "))
// Don't display deprecated commands in the Subcommands list
&& !sig.usage.starts_with("Deprecated command")
// Don't display removed/deprecated commands in the Subcommands list
&& !matches!(sig.category, Category::Removed)
{
subcommands.push(format!(" {C}{}{RESET} - {}", sig.name, sig.usage));
}

View file

@ -713,7 +713,7 @@ impl EngineState {
for decl in &overlay_frame.decls {
if overlay_frame.visibility.is_decl_id_visible(decl.1) && predicate(decl.0) {
let command = self.get_decl(*decl.1);
if ignore_deprecated && command.signature().category == Category::Deprecated {
if ignore_deprecated && command.signature().category == Category::Removed {
continue;
}
output.push((decl.0.clone(), Some(command.usage().to_string())));
@ -1713,8 +1713,7 @@ impl<'a> StateWorkingSet<'a> {
for decl in &overlay_frame.decls {
if overlay_frame.visibility.is_decl_id_visible(decl.1) && predicate(decl.0) {
let command = self.get_decl(*decl.1);
if ignore_deprecated && command.signature().category == Category::Deprecated
{
if ignore_deprecated && command.signature().category == Category::Removed {
continue;
}
output.push((decl.0.clone(), Some(command.usage().to_string())));

View file

@ -982,30 +982,17 @@ pub enum ShellError {
#[diagnostic()]
OutsideSpannedLabeledError(#[source_code] String, String, String, #[label("{2}")] Span),
/// Attempted to use a deprecated command.
/// Attempted to use a command that has been removed from Nushell.
///
/// ## Resolution
///
/// Check the help for the new suggested command and update your script accordingly.
#[error("Deprecated command {0}")]
#[diagnostic(code(nu::shell::deprecated_command))]
DeprecatedCommand(
#[error("Removed command: {0}")]
#[diagnostic(code(nu::shell::removed_command))]
RemovedCommand(
String,
String,
#[label = "'{0}' is deprecated. Please use '{1}' instead."] Span,
),
/// Attempted to use a deprecated parameter.
///
/// ## Resolution
///
/// Check the help for the command and update your script accordingly.
#[error("Deprecated parameter {0}")]
#[diagnostic(code(nu::shell::deprecated_command))]
DeprecatedParameter(
String,
String,
#[label = "Parameter '{0}' is deprecated. Please use '{1}' instead."] Span,
#[label = "'{0}' has been removed from Nushell. Please use '{1}' instead."] Span,
),
/// Non-Unicode input received.

View file

@ -49,7 +49,7 @@ pub enum Category {
Date,
Debug,
Default,
Deprecated,
Removed,
Env,
Experimental,
FileSystem,
@ -81,7 +81,7 @@ impl std::fmt::Display for Category {
Category::Date => "date",
Category::Debug => "debug",
Category::Default => "default",
Category::Deprecated => "deprecated",
Category::Removed => "removed",
Category::Env => "env",
Category::Experimental => "experimental",
Category::FileSystem => "filesystem",