Add a project path CLI option

This commit is contained in:
2025-07-21 11:56:20 -05:00
parent 8cfc6605c9
commit fc0d1b569c
2 changed files with 15 additions and 4 deletions

View File

@@ -7,6 +7,12 @@ pub struct Args {
pub gitea_url: Option<String>, pub gitea_url: Option<String>,
#[arg(short = 'r', long = "repo", env = "GTTOOL_FQRN")] #[arg(short = 'r', long = "repo", env = "GTTOOL_FQRN")]
pub repo: Option<String>, pub repo: Option<String>,
#[arg(
short = 'p',
long = "project",
help = "Path to project (relative or absolute). Used to select configuration."
)]
pub project: Option<String>,
#[command(subcommand)] #[command(subcommand)]
pub command: Commands, pub command: Commands,

View File

@@ -1,4 +1,4 @@
use std::path; use std::path::{self, PathBuf};
use gt_tool::cli::Args; use gt_tool::cli::Args;
use gt_tool::structs::release::{CreateReleaseOption, Release}; use gt_tool::structs::release::{CreateReleaseOption, Release};
@@ -14,10 +14,15 @@ async fn main() -> Result<(), gt_tool::Error> {
// TODO: Heuristics to guess project path // TODO: Heuristics to guess project path
// See issue #8: https://git.gelvin.dev/robert/gt-tool/issues/8 // See issue #8: https://git.gelvin.dev/robert/gt-tool/issues/8
let pwd = std::env::current_dir() let project_path =
.map_err(|_e| gt_tool::Error::WrappedConfigErr(gt_tool::config::Error::CouldntReadFile))?; 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( 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..."), .expect("I assumed the path can be UTF-8, but that didn't work out..."),
gt_tool::config::default_paths(), gt_tool::config::default_paths(),
)?; )?;