on master help sign in
Add --config-file option
commit8dc7e2efa349e372ee359ce38fe6c5555c2d294d authorsharkdp <davidpeter@web.de> dateWed 17 Oct 2018, 23:02 (8 years ago) parent10965a6
3 files changed+19−2
src/clap_app.rs+8 src/config.rs+6−2 src/main.rs+5
src/clap_app.rs+8
@@ -265,6 +265,14 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
265265 .hidden(true)
266266 .help("Do not use the configuration file"),
267267 )
268+ .arg(
269+ Arg::with_name("config-file")
270+ .long("config-file")
271+ .conflicts_with("list-languages")
272+ .conflicts_with("list-themes")
273+ .hidden(true)
274+ .help("Show path to the configuration file"),
275+ )
268276 .subcommand(
269277 SubCommand::with_name("cache")
270278 .about("Modify the syntax-definition and theme cache")
src/config.rs+6−2
@@ -1,16 +1,20 @@
11use std::env;
22use std::ffi::OsString;
33use std::fs;
4+use std::path::PathBuf;
45
56use shell_words;
67
78use dirs::PROJECT_DIRS;
89use util::transpose;
910
11+pub fn config_file() -> PathBuf {
12+ PROJECT_DIRS.config_dir().join("config")
13+}
14+
1015pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseError> {
11− let config_file = PROJECT_DIRS.config_dir().join("config");
1216 Ok(transpose(
13− fs::read_to_string(config_file)
17+ fs::read_to_string(config_file())
1418 .ok()
1519 .map(|content| get_args_from_str(&content)),
1620 )?
src/main.rs+5
@@ -50,6 +50,7 @@ use ansi_term::Style;
5050
5151use app::{App, Config};
5252use assets::{clear_assets, config_dir, HighlightingAssets};
53+use config::config_file;
5354use controller::Controller;
5455use inputfile::InputFile;
5556use style::{OutputComponent, OutputComponents};
@@ -224,6 +225,10 @@ fn run() -> Result<bool> {
224225 } else if app.matches.is_present("list-themes") {
225226 list_themes(&config)?;
226227
228+ Ok(true)
229+ } else if app.matches.is_present("config-file") {
230+ println!("{}", config_file().to_string_lossy());
231+
227232 Ok(true)
228233 } else {
229234 run_controller(&config)