aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart/src/commands.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-05 16:51:50 +0900
committernsfisis <nsfisis@gmail.com>2026-05-05 16:51:50 +0900
commit4f78e6c6497135cbc2923089ee26f5a50e43f06a (patch)
tree72d0bf2e188d5675d895b1d2aace447dd585b748 /crates/mozart/src/commands.rs
parent2ad57b7efb685040b24d93aab5b81ddfbd0ebefb (diff)
downloadphp-mozart-4f78e6c6497135cbc2923089ee26f5a50e43f06a.tar.gz
php-mozart-4f78e6c6497135cbc2923089ee26f5a50e43f06a.tar.zst
php-mozart-4f78e6c6497135cbc2923089ee26f5a50e43f06a.zip
refactor(commands): consolidate working_dir resolution into Cli method
Diffstat (limited to 'crates/mozart/src/commands.rs')
-rw-r--r--crates/mozart/src/commands.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/crates/mozart/src/commands.rs b/crates/mozart/src/commands.rs
index 504e38d..44ca07d 100644
--- a/crates/mozart/src/commands.rs
+++ b/crates/mozart/src/commands.rs
@@ -62,7 +62,7 @@ pub struct Cli {
/// If specified, use the given directory as working directory
#[arg(short = 'd', long = "working-dir", global = true)]
- pub working_dir: Option<String>,
+ working_dir: Option<String>,
/// Prevent use of the cache
#[arg(long, global = true)]
@@ -85,6 +85,18 @@ pub struct Cli {
pub no_ansi: bool,
}
+impl Cli {
+ /// Resolve the working directory: returns `--working-dir` if set, otherwise
+ /// the current working directory.
+ pub fn working_dir(&self) -> anyhow::Result<std::path::PathBuf> {
+ match &self.working_dir {
+ Some(dir) => Ok(std::path::PathBuf::from(dir)),
+ None => std::env::current_dir()
+ .map_err(|e| anyhow::anyhow!("Failed to get current directory: {}", e)),
+ }
+ }
+}
+
#[derive(clap::Subcommand)]
pub enum Commands {
/// Shows a short information about Mozart