@@ -99,7 +99,7 @@ fn is_flag(arg: &OsStr, options: &mut Options) -> bool {
99
99
///
100
100
/// - Vector of non-flag arguments.
101
101
/// - [`Options`], describing how teh arguments should be interpreted.
102
- fn filter_flags ( mut args : impl uucore :: Args ) ->( Vec < OsString > , Options ) {
102
+ fn filter_flags ( mut args : impl Iterator < Item = OsString > ) ->( Vec < OsString > , Options ) {
103
103
let mut arguments =Vec :: with_capacity ( args. size_hint ( ) . 0 ) ;
104
104
let mut options =Options :: default ( ) ;
105
105
@@ -124,7 +124,7 @@ fn filter_flags(mut args: impl uucore::Args) -> (Vec<OsString>, Options) {
124
124
#[ uucore:: main]
125
125
pub fn uumain ( args : impl uucore:: Args ) ->UResult < ( ) > {
126
126
// args[0] is the name of the binary.
127
- let mut args = args. skip ( 1 ) . peekable ( ) ;
127
+ let args: Vec < OsString > = args. skip ( 1 ) . collect ( ) ;
128
128
129
129
// Check POSIX compatibility mode
130
130
//
@@ -140,13 +140,25 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
140
140
let is_posixly_correct = env:: var_os ( "POSIXLY_CORRECT" ) . is_some ( ) ;
141
141
142
142
let ( args, options) =match is_posixly_correct{
143
+ // If POSIXLY_CORRECT is not set and the first argument
144
+ // is `--help`, GNU coreutils prints the help message.
145
+ //
146
+ // Verify this using:
147
+ //
148
+ // POSIXLY_CORRECT=1 echo --help
149
+ // echo --help
150
+ false if args. len ( ) ==1 && args[ 0 ] =="--help" =>{
151
+ uu_app ( ) . print_help ( ) ?;
152
+ return Ok ( ( ) ) ;
153
+ }
154
+
143
155
// if POSIXLY_CORRECT is not set we filter the flags normally
144
- false =>filter_flags ( args) ,
156
+ false =>filter_flags ( args. into_iter ( ) ) ,
145
157
146
- true if args. peek ( ) . is_some_and ( |arg| arg =="-n" ) =>{
158
+ true if args. first ( ) . is_some_and ( |arg| arg =="-n" ) =>{
147
159
// if POSIXLY_CORRECT is set and the first argument is the "-n" flag
148
160
// we filter flags normally but 'escaped' is activated nonetheless.
149
- let ( args, _) =filter_flags ( args) ;
161
+ let ( args, _) =filter_flags ( args. into_iter ( ) ) ;
150
162
(
151
163
args,
152
164
Options {
@@ -159,7 +171,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
159
171
true =>{
160
172
// if POSIXLY_CORRECT is set and the first argument is not the "-n" flag
161
173
// we just collect all arguments as every argument is considered an argument.
162
- ( args. collect ( ) , Options :: posixly_correct_default ( ) )
174
+ ( args, Options :: posixly_correct_default ( ) )
163
175
}
164
176
} ;
165
177