diff options
Diffstat (limited to 'dotup_cli/src')
| -rw-r--r-- | dotup_cli/src/commands/utils.rs | 14 | ||||
| -rw-r--r-- | dotup_cli/src/main.rs | 18 |
2 files changed, 26 insertions, 6 deletions
diff --git a/dotup_cli/src/commands/utils.rs b/dotup_cli/src/commands/utils.rs index 4160078..706266e 100644 --- a/dotup_cli/src/commands/utils.rs +++ b/dotup_cli/src/commands/utils.rs | |||
| @@ -2,6 +2,8 @@ use std::path::{Path, PathBuf}; | |||
| 2 | 2 | ||
| 3 | use crate::prelude::*; | 3 | use crate::prelude::*; |
| 4 | 4 | ||
| 5 | const DEFAULT_DEPOT_NAME: &str = "depot.toml"; | ||
| 6 | |||
| 5 | pub fn home_directory() -> anyhow::Result<PathBuf> { | 7 | pub fn home_directory() -> anyhow::Result<PathBuf> { |
| 6 | match std::env::var("HOME") { | 8 | match std::env::var("HOME") { |
| 7 | Ok(val) => Ok(PathBuf::from(val)), | 9 | Ok(val) => Ok(PathBuf::from(val)), |
| @@ -12,6 +14,18 @@ pub fn home_directory() -> anyhow::Result<PathBuf> { | |||
| 12 | } | 14 | } |
| 13 | } | 15 | } |
| 14 | 16 | ||
| 17 | pub fn find_archive_path() -> anyhow::Result<PathBuf> { | ||
| 18 | let mut start = PathBuf::new(); | ||
| 19 | while { | ||
| 20 | start.push(DEFAULT_DEPOT_NAME); | ||
| 21 | !start.is_file() | ||
| 22 | } { | ||
| 23 | start.pop(); | ||
| 24 | start.push(".."); | ||
| 25 | } | ||
| 26 | Ok(start.canonicalize()?) | ||
| 27 | } | ||
| 28 | |||
| 15 | pub fn write_archive(path: impl AsRef<Path>, archive: &Archive) -> anyhow::Result<()> { | 29 | pub fn write_archive(path: impl AsRef<Path>, archive: &Archive) -> anyhow::Result<()> { |
| 16 | let path = path.as_ref(); | 30 | let path = path.as_ref(); |
| 17 | log::debug!("Writing archive to {}", path.display()); | 31 | log::debug!("Writing archive to {}", path.display()); |
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 { | |||
| 12 | } | 12 | } |
| 13 | 13 | ||
| 14 | use clap::{AppSettings, Clap}; | 14 | use clap::{AppSettings, Clap}; |
| 15 | use commands::utils; | ||
| 15 | use flexi_logger::Logger; | 16 | use flexi_logger::Logger; |
| 16 | use std::{ | 17 | use std::{ |
| 17 | collections::HashMap, | 18 | collections::HashMap, |
| @@ -21,14 +22,15 @@ use std::{ | |||
| 21 | 22 | ||
| 22 | use prelude::*; | 23 | use prelude::*; |
| 23 | 24 | ||
| 24 | const DEFAULT_DEPOT_NAME: &str = "depot.toml"; | ||
| 25 | |||
| 26 | #[derive(Clap)] | 25 | #[derive(Clap)] |
| 27 | #[clap(setting = AppSettings::ColoredHelp)] | 26 | #[clap(setting = AppSettings::ColoredHelp)] |
| 28 | struct Opts { | 27 | struct Opts { |
| 29 | /// Path to the depot file. | 28 | /// Path to the depot file. |
| 30 | #[clap(long, default_value = DEFAULT_DEPOT_NAME)] | 29 | /// |
| 31 | depot: PathBuf, | 30 | /// By default it will try to find a file named "depot.toml" in the current directory or any of |
| 31 | /// the parent directories. | ||
| 32 | #[clap(long)] | ||
| 33 | depot: Option<PathBuf>, | ||
| 32 | 34 | ||
| 33 | /// Disable output to the console | 35 | /// Disable output to the console |
| 34 | #[clap(short, long)] | 36 | #[clap(short, long)] |
| @@ -76,9 +78,13 @@ fn main() -> anyhow::Result<()> { | |||
| 76 | .start()?; | 78 | .start()?; |
| 77 | } | 79 | } |
| 78 | 80 | ||
| 79 | let config = Config { | 81 | let archive_path = match opts.depot { |
| 80 | archive_path: opts.depot, | 82 | Some(path) => path, |
| 83 | None => utils::find_archive_path()?, | ||
| 81 | }; | 84 | }; |
| 85 | log::debug!("Archive path : {}", archive_path.display()); | ||
| 86 | |||
| 87 | let config = Config { archive_path }; | ||
| 82 | 88 | ||
| 83 | match opts.subcmd { | 89 | match opts.subcmd { |
| 84 | SubCommand::Init(opts) => commands::init::main(config, opts), | 90 | SubCommand::Init(opts) => commands::init::main(config, opts), |
