From 21c234735ebf74899ce9a98cb46d9500b3f51e89 Mon Sep 17 00:00:00 2001 From: diogo464 Date: Fri, 9 Jul 2021 10:03:42 -0400 Subject: Search parent directories for depot file. If the depot file is not specified and is not found in the current directory then it will be searched trough the parent directories until a depot file is found. --- dotup_cli/src/main.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'dotup_cli/src/main.rs') diff --git a/dotup_cli/src/main.rs b/dotup_cli/src/main.rs index 867afb4..0b4bff1 100644 --- a/dotup_cli/src/main.rs +++ b/dotup_cli/src/main.rs @@ -12,6 +12,7 @@ pub mod prelude { } use clap::{AppSettings, Clap}; +use commands::utils; use flexi_logger::Logger; use std::{ collections::HashMap, @@ -21,14 +22,15 @@ use std::{ use prelude::*; -const DEFAULT_DEPOT_NAME: &str = "depot.toml"; - #[derive(Clap)] #[clap(setting = AppSettings::ColoredHelp)] struct Opts { /// Path to the depot file. - #[clap(long, default_value = DEFAULT_DEPOT_NAME)] - depot: PathBuf, + /// + /// By default it will try to find a file named "depot.toml" in the current directory or any of + /// the parent directories. + #[clap(long)] + depot: Option, /// Disable output to the console #[clap(short, long)] @@ -76,9 +78,13 @@ fn main() -> anyhow::Result<()> { .start()?; } - let config = Config { - archive_path: opts.depot, + let archive_path = match opts.depot { + Some(path) => path, + None => utils::find_archive_path()?, }; + log::debug!("Archive path : {}", archive_path.display()); + + let config = Config { archive_path }; match opts.subcmd { SubCommand::Init(opts) => commands::init::main(config, opts), -- cgit