Skip to content

Commit

Permalink
ls: when -aA are provided, the order matters
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Mar 20, 2022
1 parent 04b219b commit 15d176b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,27 @@ impl Config {
}
}

let files = if options.is_present(options::files::ALL) {
let files = if options.is_present(options::files::ALL)
&& options.is_present(options::files::ALMOST_ALL)
{
// OK, both arguments (a & A) are provided.
// in this case, the order matters
if options.index_of(options::files::ALL) > options.index_of(options::files::ALMOST_ALL)
{
// -Aa
Files::All
} else {
// -aA
Files::AlmostAll
}
} else if options.is_present(options::files::ALL) {
// -a
Files::All
} else if options.is_present(options::files::ALMOST_ALL) {
// -A
Files::AlmostAll
} else {
// Neither
Files::Normal
};

Expand Down
22 changes: 22 additions & 0 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2869,3 +2869,25 @@ fn test_ls_context_format() {
);
}
}

#[test]
#[allow(non_snake_case)]
fn test_ls_a_A() {
let scene = TestScenario::new(util_name!());

scene
.ucmd()
.arg("-A")
.arg("-a")
.succeeds()
.stdout_contains(".")
.stdout_contains("..");

scene
.ucmd()
.arg("-a")
.arg("-A")
.succeeds()
.stdout_does_not_contain(".")
.stdout_does_not_contain("..");
}

0 comments on commit 15d176b

Please sign in to comment.