mirror of
https://github.com/sharkdp/bat.git
synced 2025-03-14 06:38:24 +00:00
Add --config-file option
This commit is contained in:
parent
10965a6122
commit
8dc7e2efa3
@ -265,6 +265,14 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
|
|||||||
.hidden(true)
|
.hidden(true)
|
||||||
.help("Do not use the configuration file"),
|
.help("Do not use the configuration file"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("config-file")
|
||||||
|
.long("config-file")
|
||||||
|
.conflicts_with("list-languages")
|
||||||
|
.conflicts_with("list-themes")
|
||||||
|
.hidden(true)
|
||||||
|
.help("Show path to the configuration file"),
|
||||||
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("cache")
|
SubCommand::with_name("cache")
|
||||||
.about("Modify the syntax-definition and theme cache")
|
.about("Modify the syntax-definition and theme cache")
|
||||||
|
@ -1,16 +1,20 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use shell_words;
|
use shell_words;
|
||||||
|
|
||||||
use dirs::PROJECT_DIRS;
|
use dirs::PROJECT_DIRS;
|
||||||
use util::transpose;
|
use util::transpose;
|
||||||
|
|
||||||
|
pub fn config_file() -> PathBuf {
|
||||||
|
PROJECT_DIRS.config_dir().join("config")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseError> {
|
pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseError> {
|
||||||
let config_file = PROJECT_DIRS.config_dir().join("config");
|
|
||||||
Ok(transpose(
|
Ok(transpose(
|
||||||
fs::read_to_string(config_file)
|
fs::read_to_string(config_file())
|
||||||
.ok()
|
.ok()
|
||||||
.map(|content| get_args_from_str(&content)),
|
.map(|content| get_args_from_str(&content)),
|
||||||
)?
|
)?
|
||||||
|
@ -50,6 +50,7 @@ use ansi_term::Style;
|
|||||||
|
|
||||||
use app::{App, Config};
|
use app::{App, Config};
|
||||||
use assets::{clear_assets, config_dir, HighlightingAssets};
|
use assets::{clear_assets, config_dir, HighlightingAssets};
|
||||||
|
use config::config_file;
|
||||||
use controller::Controller;
|
use controller::Controller;
|
||||||
use inputfile::InputFile;
|
use inputfile::InputFile;
|
||||||
use style::{OutputComponent, OutputComponents};
|
use style::{OutputComponent, OutputComponents};
|
||||||
@ -224,6 +225,10 @@ fn run() -> Result<bool> {
|
|||||||
} else if app.matches.is_present("list-themes") {
|
} else if app.matches.is_present("list-themes") {
|
||||||
list_themes(&config)?;
|
list_themes(&config)?;
|
||||||
|
|
||||||
|
Ok(true)
|
||||||
|
} else if app.matches.is_present("config-file") {
|
||||||
|
println!("{}", config_file().to_string_lossy());
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else {
|
} else {
|
||||||
run_controller(&config)
|
run_controller(&config)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user