on master help sign in
Add BAT_OPTS environment variable
commit5bff4548be2575d82e8fd1df5e55aea122c82412 authorsharkdp <davidpeter@web.de> dateThu 11 Oct 2018, 23:01 (8 years ago) parent866b9e1
2 files changed+8−3
src/app.rs+4−3 src/config.rs+4
src/app.rs+4−3
@@ -15,7 +15,7 @@ use console::Term;
1515use ansi_term;
1616
1717use assets::BAT_THEME_DEFAULT;
18−use config::get_args_from_config_file;
18+use config::{get_args_from_config_file, get_args_from_env_var};
1919use errors::*;
2020use inputfile::InputFile;
2121use line_range::LineRange;
@@ -104,8 +104,9 @@ impl App {
104104 let mut cli_args = wild::args_os();
105105
106106 // Read arguments from bats config file
107− let mut args =
108− get_args_from_config_file().chain_err(|| "Could not parse configuration file")?;
107+ let mut args = get_args_from_env_var()
108+ .unwrap_or_else(|| get_args_from_config_file())
109+ .chain_err(|| "Could not parse configuration file")?;
109110
110111 // Put the zero-th CLI argument (program name) first
111112 args.insert(0, cli_args.next().unwrap());
src/config.rs+4
@@ -17,6 +17,10 @@ pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseEr
1717 .unwrap_or(vec![]))
1818}
1919
20+pub fn get_args_from_env_var() -> Option<Result<Vec<OsString>, shell_words::ParseError>> {
21+ env::var("BAT_OPTS").ok().map(|s| get_args_from_str(&s))
22+}
23+
2024fn get_args_from_str<'a>(content: &'a str) -> Result<Vec<OsString>, shell_words::ParseError> {
2125 let args_per_line = content
2226 .split('\n')