From fc0d1b569c8b343d91278385df1a488778951bf1 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Mon, 21 Jul 2025 11:56:20 -0500 Subject: [PATCH] Add a project path CLI option --- src/cli.rs | 6 ++++++ src/main.rs | 13 +++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 4b02858..bb0923a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -7,6 +7,12 @@ pub struct Args { pub gitea_url: Option, #[arg(short = 'r', long = "repo", env = "GTTOOL_FQRN")] pub repo: Option, + #[arg( + short = 'p', + long = "project", + help = "Path to project (relative or absolute). Used to select configuration." + )] + pub project: Option, #[command(subcommand)] pub command: Commands, diff --git a/src/main.rs b/src/main.rs index 1f5ac8f..5a5b82a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::path; +use std::path::{self, PathBuf}; use gt_tool::cli::Args; use gt_tool::structs::release::{CreateReleaseOption, Release}; @@ -14,10 +14,15 @@ async fn main() -> Result<(), gt_tool::Error> { // TODO: Heuristics to guess project path // See issue #8: https://git.gelvin.dev/robert/gt-tool/issues/8 - let pwd = std::env::current_dir() - .map_err(|_e| gt_tool::Error::WrappedConfigErr(gt_tool::config::Error::CouldntReadFile))?; + let project_path = + args.project + .map(PathBuf::from) + .unwrap_or(std::env::current_dir().map_err(|_e| { + gt_tool::Error::WrappedConfigErr(gt_tool::config::Error::CouldntReadFile) + })?); let config = gt_tool::config::get_config( - pwd.to_str() + project_path + .to_str() .expect("I assumed the path can be UTF-8, but that didn't work out..."), gt_tool::config::default_paths(), )?;