From 826a914c8f043bf80ec1c77c69cffc46ab61d02b Mon Sep 17 00:00:00 2001 From: teesh3rt Date: Mon, 24 Mar 2025 20:22:33 +0200 Subject: [PATCH] feat: add the pwd command --- coreutils/src/commands/mod.rs | 1 + coreutils/src/commands/pwd.rs | 18 ++++++++++++++++++ src/registry.rs | 1 + 3 files changed, 20 insertions(+) create mode 100644 coreutils/src/commands/pwd.rs diff --git a/coreutils/src/commands/mod.rs b/coreutils/src/commands/mod.rs index f0ef483..1450631 100644 --- a/coreutils/src/commands/mod.rs +++ b/coreutils/src/commands/mod.rs @@ -15,3 +15,4 @@ command!(r#true::True); command!(r#false::False); command!(test::Test); command!(yes::Yes); +command!(pwd::Pwd); diff --git a/coreutils/src/commands/pwd.rs b/coreutils/src/commands/pwd.rs new file mode 100644 index 0000000..c2f54ed --- /dev/null +++ b/coreutils/src/commands/pwd.rs @@ -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()); + } +} diff --git a/src/registry.rs b/src/registry.rs index 0e1cbe1..7db5749 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -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