Hook up -C/--config-file option

All it does is parsing, but it's a start
This commit is contained in:
Félix Saparelli 2022-01-22 13:59:24 +13:00
parent 0ed758595f
commit 71efc29fae
5 changed files with 28 additions and 5 deletions

View file

@ -23,6 +23,7 @@ impl Clap3Compat for Arg<'_, '_> {}
const OPTSET_FILTERING: &str = "Filtering options:";
const OPTSET_COMMAND: &str = "Command options:";
const OPTSET_CONFIG: &str = "Config file options:";
const OPTSET_DEBUGGING: &str = "Debugging options:";
const OPTSET_OUTPUT: &str = "Output options:";
const OPTSET_BEHAVIOUR: &str = "Behaviour options:";
@ -32,6 +33,12 @@ pub fn get_args(tagged_filterer: bool) -> Result<ArgMatches<'static>> {
.version(crate_version!())
.about("Execute commands when watched files change")
.after_help("Use @argfile as first argument to load arguments from the file `argfile` (one argument per line) which will be inserted in place of the @argfile (further arguments on the CLI will override or add onto those in the file).")
.arg(Arg::with_name("config-file")
.help_heading(Some(OPTSET_CONFIG))
.help("Config file(s) to use")
.multiple(true)
.short("C")
.long("config"))
.arg(Arg::with_name("command")
.help_heading(Some(OPTSET_COMMAND))
.help("Command to execute")

View file

@ -199,10 +199,7 @@ mod tests {
config.commands[0].run.as_ref().unwrap().shell,
Shell::default()
);
assert_eq!(
config.commands[0].run.as_ref().unwrap().shell,
Shell::None
);
assert_eq!(config.commands[0].run.as_ref().unwrap().shell, Shell::None);
}
#[test]

View file

@ -1,6 +1,8 @@
use std::env::var;
use miette::{IntoDiagnostic, Result};
use miette::{IntoDiagnostic, Result, WrapErr};
use tokio::fs::read_to_string;
use tracing::debug;
use watchexec::{event::Event, Watchexec};
mod args;
@ -47,6 +49,21 @@ async fn main() -> Result<()> {
}
}
let mut configs = Vec::with_capacity(
args.occurrences_of("config-file")
.try_into()
.into_diagnostic()
.wrap_err("Too many config files")?,
);
// TODO: look for global/project config file
for path in args.values_of("config-file").unwrap_or_default() {
let content = read_to_string(path).await.into_diagnostic()?;
configs.push(config::File::parse(&content)?);
}
debug!(?configs, "loaded config files");
// TODO: merge configs
// TODO: use configs
let init = config::init(&args)?;
let mut runtime = config::runtime(&args)?;
runtime.filterer(if tagged_filterer {

View file

@ -12,6 +12,7 @@ USAGE:
FLAGS:
-c, --clear Clear screen before executing command
-C, --config Config file(s) to use
-h, --help Prints help information
--no-default-ignore Skip auto-ignoring of commonly ignored globs
--no-environment Do not set WATCHEXEC_*_PATH environment variables for the command

View file

@ -11,6 +11,7 @@ USAGE:
FLAGS:
-c, --clear Clear screen before executing command
-C, --config Config file(s) to use
-h, --help Prints help information
--no-default-ignore Skip auto-ignoring of commonly ignored globs
--no-environment Do not set WATCHEXEC_*_PATH environment variables for the command