diff --git a/bin/oli/src/bin/oli.rs b/bin/oli/src/bin/oli.rs index 61685b991d17..99ba3d276307 100644 --- a/bin/oli/src/bin/oli.rs +++ b/bin/oli/src/bin/oli.rs @@ -24,35 +24,19 @@ use std::env; use std::ffi::OsStr; -use std::ffi::OsString; use std::path::PathBuf; use anyhow::anyhow; use anyhow::Result; -use clap::value_parser; use oli::commands::OliSubcommand; #[derive(Debug, clap::Parser)] #[command(about, version)] pub struct Oli { - /// Path to the config file. - #[arg( - long, - global = true, - default_value = default_config_path(), - value_parser = value_parser!(PathBuf) - )] - config: Option, - #[command(subcommand)] subcommand: OliSubcommand, } -fn default_config_path() -> OsString { - let d = dirs::config_dir().expect("unknown config dir"); - d.join("oli/config.toml").as_os_str().to_owned() -} - #[tokio::main] async fn main() -> Result<()> { // Guard against infinite proxy recursion. This mostly happens due to diff --git a/bin/oli/src/commands/cat.rs b/bin/oli/src/commands/cat.rs index 35f9910ceb62..55456300caaa 100644 --- a/bin/oli/src/commands/cat.rs +++ b/bin/oli/src/commands/cat.rs @@ -20,6 +20,7 @@ use std::path::PathBuf; use anyhow::Result; use futures::io; +use crate::commands::default_config_path; use crate::config::Config; #[derive(Debug, clap::Parser)] @@ -30,7 +31,11 @@ use crate::config::Config; )] pub struct CatCmd { /// Path to the config file. - #[arg(from_global)] + #[arg( + long, + default_value = default_config_path(), + value_parser = clap::value_parser!(PathBuf) + )] pub config: PathBuf, #[arg()] pub target: String, diff --git a/bin/oli/src/commands/cp.rs b/bin/oli/src/commands/cp.rs index 35460b37da99..583b69ea202b 100644 --- a/bin/oli/src/commands/cp.rs +++ b/bin/oli/src/commands/cp.rs @@ -22,13 +22,18 @@ use anyhow::Result; use futures::AsyncWriteExt; use futures::TryStreamExt; +use crate::commands::default_config_path; use crate::config::Config; #[derive(Debug, clap::Parser)] #[command(name = "cp", about = "Copy object", disable_version_flag = true)] pub struct CopyCmd { /// Path to the config file. - #[arg(from_global)] + #[arg( + long, + default_value = default_config_path(), + value_parser = clap::value_parser!(PathBuf) + )] pub config: PathBuf, #[arg()] pub source: String, diff --git a/bin/oli/src/commands/ls.rs b/bin/oli/src/commands/ls.rs index 4c24418f6bf6..c3a6253b1184 100644 --- a/bin/oli/src/commands/ls.rs +++ b/bin/oli/src/commands/ls.rs @@ -20,13 +20,18 @@ use std::path::PathBuf; use anyhow::Result; use futures::TryStreamExt; +use crate::commands::default_config_path; use crate::config::Config; #[derive(Debug, clap::Parser)] #[command(name = "ls", about = "List object", disable_version_flag = true)] pub struct LsCmd { /// Path to the config file. - #[arg(from_global)] + #[arg( + long, + default_value = default_config_path(), + value_parser = clap::value_parser!(PathBuf) + )] pub config: PathBuf, #[arg()] pub target: String, diff --git a/bin/oli/src/commands/mod.rs b/bin/oli/src/commands/mod.rs index 0971a42f4551..3d65d617c0ed 100644 --- a/bin/oli/src/commands/mod.rs +++ b/bin/oli/src/commands/mod.rs @@ -17,12 +17,19 @@ //! Commands provides the implementation of each command. +use std::ffi::OsString; + pub mod cat; pub mod cp; pub mod ls; pub mod rm; pub mod stat; +fn default_config_path() -> OsString { + let d = dirs::config_dir().expect("unknown config dir"); + d.join("oli/config.toml").as_os_str().to_owned() +} + #[derive(Debug, clap::Subcommand)] pub enum OliSubcommand { Cat(cat::CatCmd), diff --git a/bin/oli/src/commands/rm.rs b/bin/oli/src/commands/rm.rs index fd91261b1eb7..581e609edc2b 100644 --- a/bin/oli/src/commands/rm.rs +++ b/bin/oli/src/commands/rm.rs @@ -19,13 +19,18 @@ use std::path::PathBuf; use anyhow::Result; +use crate::commands::default_config_path; use crate::config::Config; #[derive(Debug, clap::Parser)] #[command(name = "rm", about = "Remove object", disable_version_flag = true)] pub struct RmCmd { /// Path to the config file. - #[arg(from_global)] + #[arg( + long, + default_value = default_config_path(), + value_parser = clap::value_parser!(PathBuf) + )] pub config: PathBuf, #[arg()] pub target: String, diff --git a/bin/oli/src/commands/stat.rs b/bin/oli/src/commands/stat.rs index 1b16281e3f7f..26c24fe4a977 100644 --- a/bin/oli/src/commands/stat.rs +++ b/bin/oli/src/commands/stat.rs @@ -19,6 +19,7 @@ use std::path::PathBuf; use anyhow::Result; +use crate::commands::default_config_path; use crate::config::Config; #[derive(Debug, clap::Parser)] @@ -29,7 +30,11 @@ use crate::config::Config; )] pub struct StatCmd { /// Path to the config file. - #[arg(from_global)] + #[arg( + long, + default_value = default_config_path(), + value_parser = clap::value_parser!(PathBuf) + )] pub config: PathBuf, #[arg()] pub target: String,