feat: add the pwd command
This commit is contained in:
parent
be4cbd760b
commit
826a914c8f
3 changed files with 20 additions and 0 deletions
|
|
@ -15,3 +15,4 @@ command!(r#true::True);
|
|||
command!(r#false::False);
|
||||
command!(test::Test);
|
||||
command!(yes::Yes);
|
||||
command!(pwd::Pwd);
|
||||
|
|
|
|||
18
coreutils/src/commands/pwd.rs
Normal file
18
coreutils/src/commands/pwd.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use boxutils::args::ArgParser;
|
||||
use boxutils::commands::Command;
|
||||
|
||||
pub struct Pwd;
|
||||
|
||||
impl Command for Pwd {
|
||||
fn execute(&self) {
|
||||
let args = ArgParser::builder().add_flag("--help").parse_args("yes");
|
||||
|
||||
if args.get_flag("--help") {
|
||||
println!("Usage: pwd");
|
||||
return;
|
||||
}
|
||||
|
||||
let pwd = std::env::current_dir().unwrap();
|
||||
println!("{}", pwd.display());
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ pub fn get_registry() -> CommandRegistry {
|
|||
);
|
||||
registry.register("[", Box::new(coreutils::commands::Test::with_bracket()));
|
||||
registry.register("yes", Box::new(coreutils::commands::Yes));
|
||||
registry.register("pwd", Box::new(coreutils::commands::Pwd));
|
||||
registry.register("box", Box::new(Boxcmd));
|
||||
|
||||
registry
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue