ls: add -A flag
This commit is contained in:
parent
bb615b8061
commit
17111b96e1
12
src/ls.rs
12
src/ls.rs
|
@ -5,6 +5,7 @@ fn main(){
|
|||
let args: Vec<String> = env::args().collect();
|
||||
let pwd = env::current_dir().unwrap();
|
||||
let mut show_hidden = false;
|
||||
let mut show_prev_and_current = false;
|
||||
let mut dir = pwd.to_str();
|
||||
for arg in 1..args.len() {
|
||||
match args[arg].as_str() {
|
||||
|
@ -13,17 +14,22 @@ fn main(){
|
|||
},
|
||||
"-a" | "--all" => {
|
||||
show_hidden = true;
|
||||
show_prev_and_current = true;
|
||||
},
|
||||
"-A" | "--almost-all" => {
|
||||
show_hidden = true;
|
||||
show_prev_and_current = false;
|
||||
}
|
||||
arg => {
|
||||
dir = Some(arg);
|
||||
},
|
||||
}
|
||||
}
|
||||
list_dir(dir.unwrap().to_string(), show_hidden);
|
||||
list_dir(dir.unwrap().to_string(), show_hidden, show_prev_and_current);
|
||||
}
|
||||
fn list_dir(arg: String, show_hidden: bool) {
|
||||
fn list_dir(arg: String, show_hidden: bool, show_prev_and_current: bool) {
|
||||
let files = fs::read_dir(arg.clone()).unwrap();
|
||||
if show_hidden {
|
||||
if show_hidden && show_prev_and_current {
|
||||
println!(".");
|
||||
println!("..");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue