@@ -4,8 +4,8 @@ use nu_engine::CallExt;
4
4
use nu_protocol:: ast:: Call ;
5
5
use nu_protocol:: engine:: { Command , EngineState , Stack } ;
6
6
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 ,
9
9
} ;
10
10
use quick_xml:: events:: { BytesEnd , BytesStart , BytesText , Event } ;
11
11
use std:: io:: Cursor ;
@@ -25,9 +25,15 @@ impl Command for ToXml {
25
25
. named (
26
26
"pretty" ,
27
27
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. " ,
29
29
Some ( 'p' ) ,
30
30
)
31
+ . named (
32
+ "indent" ,
33
+ SyntaxShape :: Int ,
34
+ "Formats the XML text with the provided indentation setting" ,
35
+ Some ( 'i' ) ,
36
+ )
31
37
. category ( Category :: Formats )
32
38
}
33
39
@@ -60,7 +66,7 @@ Additionally any field which is: empty record, empty list or null, can be omitte
60
66
} ,
61
67
Example {
62
68
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"# ,
64
70
result: Some ( Value :: test_string(
65
71
"<note>\n <remember>Event</remember>\n </note>" ,
66
72
) ) ,
@@ -80,9 +86,35 @@ Additionally any field which is: empty record, empty list or null, can be omitte
80
86
input : PipelineData ,
81
87
) -> Result < PipelineData , ShellError > {
82
88
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
+ }
83
101
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
+ } ;
84
116
let input = input. try_expand_range ( ) ?;
85
- to_xml ( input, head, pretty )
117
+ to_xml ( input, head, indent )
86
118
}
87
119
}
88
120
@@ -373,9 +405,9 @@ fn to_xml_text<W: Write>(
373
405
fn to_xml (
374
406
input : PipelineData ,
375
407
head : Span ,
376
- pretty : Option < Spanned < i64 > > ,
408
+ indent : Option < Spanned < i64 > > ,
377
409
) -> Result < PipelineData , ShellError > {
378
- let mut w = pretty . as_ref ( ) . map_or_else (
410
+ let mut w = indent . as_ref ( ) . map_or_else (
379
411
|| quick_xml:: Writer :: new ( Cursor :: new ( Vec :: new ( ) ) ) ,
380
412
|p| quick_xml:: Writer :: new_with_indent ( Cursor :: new ( Vec :: new ( ) ) , b' ' , p. item as usize ) ,
381
413
) ;
0 commit comments