diff options
author | Niklas Claesson <nicke.claesson@gmail.com> | 2017-05-29 02:42:36 +0200 |
---|---|---|
committer | Joe Wilm <jwilm@users.noreply.github.com> | 2017-05-28 17:42:36 -0700 |
commit | 81116fb8a4f91f28b5751827e7bcda22f6fcbaf0 (patch) | |
tree | b9b446b5f8ed18c31189eb45f24f02ffe767657f /src/cli.rs | |
parent | 13eac6b673a089afe6f15adb73d6812916c73f73 (diff) | |
download | alacritty-81116fb8a4f91f28b5751827e7bcda22f6fcbaf0.tar.gz alacritty-81116fb8a4f91f28b5751827e7bcda22f6fcbaf0.zip |
Add config file as cli option (#576)
* Parse cli arguments before configuration file
Parsing the cli arguments before the configuration file allows `--help`
and `--version` to be used even if the configuration file is broken.
* Add configuration file to command line arguments
This commit adds a new command line flag `--config-file` to override the default
configuration file location. If the specified file is unavailable,
Alacritty will quit instead of generating a fallback. If the specified
file is invalid, i.e. /dev/null, the compiled in defaults will be loaded
instead.
Diffstat (limited to 'src/cli.rs')
-rw-r--r-- | src/cli.rs | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -15,7 +15,8 @@ extern crate log; use clap::{Arg, App}; use index::{Line, Column}; use config::{Dimensions, Shell}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; +use std::borrow::Cow; const DEFAULT_TITLE: &'static str = "Alacritty"; @@ -28,6 +29,7 @@ pub struct Options { pub log_level: log::LogLevelFilter, pub command: Option<Shell<'static>>, pub working_dir: Option<PathBuf>, + pub config: Option<PathBuf>, } impl Default for Options { @@ -40,6 +42,7 @@ impl Default for Options { log_level: log::LogLevelFilter::Warn, command: None, working_dir: None, + config: None, } } } @@ -82,6 +85,10 @@ impl Options { .long("working-directory") .takes_value(true) .help("Start the shell in the specified working directory")) + .arg(Arg::with_name("config-file") + .long("config-file") + .takes_value(true) + .help("Specify alternative configuration file [default: $XDG_CONFIG_HOME/alacritty/alacritty.yml]")) .arg(Arg::with_name("command") .short("e") .multiple(true) @@ -128,6 +135,10 @@ impl Options { options.working_dir = Some(PathBuf::from(dir.to_string())); } + if let Some(path) = matches.value_of("config-file") { + options.config = Some(PathBuf::from(path.to_string())); + } + if let Some(mut args) = matches.values_of("command") { // The following unwrap is guaranteed to succeed. // If 'command' exists it must also have a first item since @@ -147,4 +158,8 @@ impl Options { pub fn command(&self) -> Option<&Shell> { self.command.as_ref() } + + pub fn config_path(&self) -> Option<Cow<Path>> { + self.config.as_ref().map(|p| Cow::Borrowed(p.as_path())) + } } |