Skip to content

Commit 9f14479

Browse files
authored
Deprecate to xml --pretty {int} in favor of --indent {int} (#10660)
Fixes #10644 ## the deprecation errors - using `--pretty` alone` will run the command and give a warning ```nushell > {tag: note content : [{tag: remember content : [Event]}]} | to xml --pretty 4 Error: × Deprecated option ╭─[entry #7:1:1] 1 │ {tag: note content : [{tag: remember content : [Event]}]} | to xml --pretty 4 · ───┬── · ╰── `to xml --pretty {int}` is deprecated and will be removed in 0.87. ╰──── help: Please use `--indent {int}` instead. <note> <remember>Event</remember> </note> ``` - using `--pretty` and `--indent` will give the deprecation warning and throw an error ```nushell > {tag: note content : [{tag: remember content : [Event]}]} | to xml --pretty 4 --indent 4 Error: × Deprecated option ╭─[entry #9:1:1] 1 │ {tag: note content : [{tag: remember content : [Event]}]} | to xml --pretty 4 --indent 4 · ───┬── · ╰── `to xml --pretty {int}` is deprecated and will be removed in 0.87. ╰──── help: Please use `--indent {int}` instead. Error: nu:🐚:incompatible_parameters × Incompatible parameters. ╭─[entry #9:1:1] 1 │ {tag: note content : [{tag: remember content : [Event]}]} | to xml --pretty 4 --indent 4 · ┬ ┬ · │ ╰── and --indent · ╰── Cannot pass --pretty ╰──── ```
1 parent 0b651b6 commit 9f14479

File tree

1 file changed

+39
-7
lines changed
  • crates/nu-command/src/formats/to

1 file changed

+39
-7
lines changed

crates/nu-command/src/formats/to/xml.rs

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use nu_engine::CallExt;
44
use nu_protocol::ast::Call;
55
use nu_protocol::engine::{Command, EngineState, Stack};
66
use nu_protocol::{
7-
Category, Example, IntoPipelineData, PipelineData, Record, ShellError, Signature, Span,
8-
Spanned, SyntaxShape, Type, Value,
7+
report_error_new, Category, Example, IntoPipelineData, PipelineData, Record, ShellError,
8+
Signature, Span, Spanned, SyntaxShape, Type, Value,
99
};
1010
use quick_xml::events::{BytesEnd, BytesStart, BytesText, Event};
1111
use std::io::Cursor;
@@ -25,9 +25,15 @@ impl Command for ToXml {
2525
.named(
2626
"pretty",
2727
SyntaxShape::Int,
28-
"Formats the XML text with the provided indentation setting",
28+
"DEPRECATED option, will be removed in 0.87. Please use `--indent {int}` instead.",
2929
Some('p'),
3030
)
31+
.named(
32+
"indent",
33+
SyntaxShape::Int,
34+
"Formats the XML text with the provided indentation setting",
35+
Some('i'),
36+
)
3137
.category(Category::Formats)
3238
}
3339

@@ -60,7 +66,7 @@ Additionally any field which is: empty record, empty list or null, can be omitte
6066
},
6167
Example {
6268
description: "Optionally, formats the text with a custom indentation setting",
63-
example: r#"{tag: note content : [{tag: remember content : [Event]}]} | to xml --pretty 3"#,
69+
example: r#"{tag: note content : [{tag: remember content : [Event]}]} | to xml --indent 3"#,
6470
result: Some(Value::test_string(
6571
"<note>\n <remember>Event</remember>\n</note>",
6672
)),
@@ -80,9 +86,35 @@ Additionally any field which is: empty record, empty list or null, can be omitte
8086
input: PipelineData,
8187
) -> Result<PipelineData, ShellError> {
8288
let head = call.head;
89+
if call.has_flag("pretty") {
90+
report_error_new(
91+
engine_state,
92+
&ShellError::GenericError(
93+
"Deprecated option".into(),
94+
"`to xml --pretty {int}` is deprecated and will be removed in 0.87.".into(),
95+
Some(call.head),
96+
Some("Please use `--indent {int}` instead.".into()),
97+
vec![],
98+
),
99+
);
100+
}
83101
let pretty: Option<Spanned<i64>> = call.get_flag(engine_state, stack, "pretty")?;
102+
let indent: Option<Spanned<i64>> = call.get_flag(engine_state, stack, "indent")?;
103+
let indent = match (pretty, indent) {
104+
(Some(pretty), Some(indent)) => {
105+
return Err(ShellError::IncompatibleParameters {
106+
left_message: "Cannot pass --pretty".into(),
107+
left_span: pretty.span,
108+
right_message: "and --indent".into(),
109+
right_span: indent.span,
110+
})
111+
}
112+
(Some(pretty), None) => Some(pretty),
113+
(None, Some(indent)) => Some(indent),
114+
(None, None) => None,
115+
};
84116
let input = input.try_expand_range()?;
85-
to_xml(input, head, pretty)
117+
to_xml(input, head, indent)
86118
}
87119
}
88120

@@ -373,9 +405,9 @@ fn to_xml_text<W: Write>(
373405
fn to_xml(
374406
input: PipelineData,
375407
head: Span,
376-
pretty: Option<Spanned<i64>>,
408+
indent: Option<Spanned<i64>>,
377409
) -> Result<PipelineData, ShellError> {
378-
let mut w = pretty.as_ref().map_or_else(
410+
let mut w = indent.as_ref().map_or_else(
379411
|| quick_xml::Writer::new(Cursor::new(Vec::new())),
380412
|p| quick_xml::Writer::new_with_indent(Cursor::new(Vec::new()), b' ', p.item as usize),
381413
);

0 commit comments

Comments
 (0)