Skip to content

Commit 8dc7e2e

Browse files
committed
Add --config-file option
1 parent 10965a6 commit 8dc7e2e

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/clap_app.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
use std::env;
22
use std::ffi::OsString;
33
use std::fs;
4+
use std::path::PathBuf;
45

56
use shell_words;
67

78
use dirs::PROJECT_DIRS;
89
use util::transpose;
910

11+
pub fn config_file() -> PathBuf {
12+
PROJECT_DIRS.config_dir().join("config")
13+
}
14+
1015
pub 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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ use ansi_term::Style;
5050

5151
use app::{App, Config};
5252
use assets::{clear_assets, config_dir, HighlightingAssets};
53+
use config::config_file;
5354
use controller::Controller;
5455
use inputfile::InputFile;
5556
use 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)

0 commit comments

Comments
 (0)