diff --git a/src/cli.rs b/src/cli.rs index fd1a1632c8..2445e8315a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use clap::{Parser, Subcommand}; #[derive(Default, Debug, Parser)] @@ -26,6 +28,10 @@ pub struct Args { #[clap(long, action)] /// Print version pub version: bool, + + /// Config file to use + #[clap(short, long)] + pub config: Option } #[derive(Debug, Subcommand)] diff --git a/src/config.rs b/src/config.rs index f7aa5f5223..20b89ed29b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -183,8 +183,8 @@ impl From<&SymbolStyleConfigEntry> for Style { } } -pub(crate) fn init_config() -> Res { - let config_path = config_path(); +pub(crate) fn init_config(path: Option) -> Res { + let config_path = path.unwrap_or_else(config_path); if config_path.exists() { log::info!("Loading config file at {:?}", config_path); diff --git a/src/lib.rs b/src/lib.rs index 9169e389d5..aa8ed9803a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -79,7 +79,7 @@ pub type Res = Result; pub fn run(args: &cli::Args, term: &mut Term) -> Res<()> { let dir = find_git_dir()?; let repo = open_repo(&dir)?; - let config = Rc::new(config::init_config()?); + let config = Rc::new(config::init_config(args.config.clone())?); let mut app = app::App::create( Rc::new(repo),