@@ -6,7 +6,7 @@ use clap::{Arg, ArgAction, Command};
6
6
use std:: io:: stdout;
7
7
use std:: ops:: ControlFlow ;
8
8
use uucore:: error:: { UResult , UUsageError } ;
9
- use uucore:: format:: { FormatArgument , FormatItem , parse_spec_and_escape} ;
9
+ use uucore:: format:: { FormatArgument , FormatArguments , FormatItem , parse_spec_and_escape} ;
10
10
use uucore:: { format_usage, help_about, help_section, help_usage, os_str_as_bytes, show_warning} ;
11
11
12
12
const VERSION : & str = "version" ;
@@ -39,9 +39,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
39
39
} ;
40
40
41
41
let mut format_seen = false ;
42
- let mut args = values. iter ( ) . peekable ( ) ;
43
-
44
42
// Parse and process the format string
43
+ let mut args = FormatArguments :: new ( & values) ;
45
44
for item in parse_spec_and_escape ( format) {
46
45
if let Ok ( FormatItem :: Spec ( _) ) = item {
47
46
format_seen = true ;
@@ -51,26 +50,28 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
51
50
ControlFlow :: Break ( ( ) ) => return Ok ( ( ) ) ,
52
51
} ;
53
52
}
53
+ args. start_next_batch ( ) ;
54
54
55
55
// Without format specs in the string, the iter would not consume any args,
56
56
// leading to an infinite loop. Thus, we exit early.
57
57
if !format_seen {
58
- if let Some ( arg ) = args. next ( ) {
59
- let FormatArgument :: Unparsed ( arg_str) = arg else {
58
+ if ! args. is_exhausted ( ) {
59
+ let Some ( FormatArgument :: Unparsed ( arg_str) ) = args . peek_arg ( ) else {
60
60
unreachable ! ( "All args are transformed to Unparsed" )
61
61
} ;
62
62
show_warning ! ( "ignoring excess arguments, starting with '{arg_str}'" ) ;
63
63
}
64
64
return Ok ( ( ) ) ;
65
65
}
66
66
67
- while args. peek ( ) . is_some ( ) {
67
+ while ! args. is_exhausted ( ) {
68
68
for item in parse_spec_and_escape ( format) {
69
69
match item?. write ( stdout ( ) , & mut args) ? {
70
70
ControlFlow :: Continue ( ( ) ) => { }
71
71
ControlFlow :: Break ( ( ) ) => return Ok ( ( ) ) ,
72
72
} ;
73
73
}
74
+ args. start_next_batch ( ) ;
74
75
}
75
76
76
77
Ok ( ( ) )
0 commit comments