Deprecate --numbered
from for
This commit is contained in:
parent
cfe13397ed
commit
68aea46f54
|
@ -1,5 +1,6 @@
|
||||||
use nu_engine::{command_prelude::*, get_eval_block, get_eval_expression};
|
use nu_engine::{command_prelude::*, get_eval_block, get_eval_expression};
|
||||||
use nu_protocol::engine::CommandType;
|
use nu_protocol::engine::CommandType;
|
||||||
|
use nu_protocol::ParseWarning;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct For;
|
pub struct For;
|
||||||
|
@ -30,7 +31,7 @@ impl Command for For {
|
||||||
.required("block", SyntaxShape::Block, "The block to run.")
|
.required("block", SyntaxShape::Block, "The block to run.")
|
||||||
.switch(
|
.switch(
|
||||||
"numbered",
|
"numbered",
|
||||||
"return a numbered item ($it.index and $it.item)",
|
"DEPRECATED: return a numbered item ($it.index and $it.item)",
|
||||||
Some('n'),
|
Some('n'),
|
||||||
)
|
)
|
||||||
.creates_scope()
|
.creates_scope()
|
||||||
|
@ -78,6 +79,20 @@ impl Command for For {
|
||||||
let value = eval_expression(engine_state, stack, keyword_expr)?;
|
let value = eval_expression(engine_state, stack, keyword_expr)?;
|
||||||
|
|
||||||
let numbered = call.has_flag(engine_state, stack, "numbered")?;
|
let numbered = call.has_flag(engine_state, stack, "numbered")?;
|
||||||
|
if numbered {
|
||||||
|
nu_protocol::report_error_new(
|
||||||
|
engine_state,
|
||||||
|
&ParseWarning::DeprecatedWarning {
|
||||||
|
old_command: "--numbered/-n".into(),
|
||||||
|
new_suggestion: "use `enumerate`".into(),
|
||||||
|
span: call
|
||||||
|
.get_named_arg("numbered")
|
||||||
|
.expect("`get_named_arg` found `--numbered` but still failed")
|
||||||
|
.span,
|
||||||
|
url: "See `help for` examples".into(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let ctrlc = engine_state.ctrlc.clone();
|
let ctrlc = engine_state.ctrlc.clone();
|
||||||
let engine_state = engine_state.clone();
|
let engine_state = engine_state.clone();
|
||||||
|
@ -198,8 +213,7 @@ impl Command for For {
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Number each item and print a message",
|
description: "Number each item and print a message",
|
||||||
example:
|
example: r#"for $it in (['bob' 'fred'] | enumerate) { print $"($it.index) is ($it.item)" }"#,
|
||||||
"for $it in ['bob' 'fred'] --numbered { print $\"($it.index) is ($it.item)\" }",
|
|
||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
|
@ -10,7 +10,7 @@ pub enum ParseWarning {
|
||||||
DeprecatedWarning {
|
DeprecatedWarning {
|
||||||
old_command: String,
|
old_command: String,
|
||||||
new_suggestion: String,
|
new_suggestion: String,
|
||||||
#[label("`{old_command}` is deprecated and will be removed in 0.94. Please {new_suggestion} instead")]
|
#[label("`{old_command}` is deprecated and will be removed in a future release. Please {new_suggestion} instead")]
|
||||||
span: Span,
|
span: Span,
|
||||||
url: String,
|
url: String,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user