Compare commits

...

2 Commits

Author SHA1 Message Date
Greg Shuflin
b80fb1e879 Use clap ValueParser for dump format 2024-06-26 20:29:10 -07:00
Casey Rodarmor
570d3058cf
Link to modules when first introduced in readme (#2193) 2024-06-25 21:59:42 +00:00
3 changed files with 9 additions and 25 deletions

View File

@ -656,8 +656,8 @@ Available recipes:
lint
```
Recipes in submodules can be listed with `just --list PATH`, where `PATH` is a
space- or `::`-separated module path:
Recipes in [submodules](#modules1190) can be listed with `just --list PATH`,
where `PATH` is a space- or `::`-separated module path:
```
$ cat justfile
@ -3145,7 +3145,7 @@ import? 'foo/bar.just'
Missing source files for optional imports do not produce an error.
### Modules <sup>1.19.0</sup>
### Modules<sup>1.19.0</sup>
A `justfile` can declare modules using `mod` statements. `mod` statements are
currently unstable, so you'll need to use the `--unstable` flag, or set the

View File

@ -131,9 +131,7 @@ mod arg {
COMMAND_COLOR_YELLOW,
];
pub(crate) const DUMP_FORMAT_JSON: &str = "json";
pub(crate) const DUMP_FORMAT_JUST: &str = "just";
pub(crate) const DUMP_FORMAT_VALUES: &[&str] = &[DUMP_FORMAT_JUST, DUMP_FORMAT_JSON];
}
impl Config {
@ -225,7 +223,7 @@ impl Config {
.long("dump-format")
.env("JUST_DUMP_FORMAT")
.action(ArgAction::Set)
.value_parser(PossibleValuesParser::new(arg::DUMP_FORMAT_VALUES))
.value_parser(clap::value_parser!(DumpFormat))
.default_value(arg::DUMP_FORMAT_JUST)
.value_name("FORMAT")
.help("Dump justfile as <FORMAT>"),
@ -567,23 +565,6 @@ impl Config {
}
}
fn dump_format_from_matches(matches: &ArgMatches) -> ConfigResult<DumpFormat> {
let value =
matches
.get_one::<String>(arg::DUMP_FORMAT)
.ok_or_else(|| ConfigError::Internal {
message: "`--dump-format` had no value".to_string(),
})?;
match value.as_str() {
arg::DUMP_FORMAT_JSON => Ok(DumpFormat::Json),
arg::DUMP_FORMAT_JUST => Ok(DumpFormat::Just),
_ => Err(ConfigError::Internal {
message: format!("Invalid argument `{value}` to --dump-format."),
}),
}
}
fn parse_module_path(values: ValuesRef<String>) -> ConfigResult<ModulePath> {
let path = values.clone().map(|s| (*s).as_str()).collect::<Vec<&str>>();
@ -753,7 +734,10 @@ impl Config {
.map(Into::into),
dotenv_path: matches.get_one::<PathBuf>(arg::DOTENV_PATH).map(Into::into),
dry_run: matches.get_flag(arg::DRY_RUN),
dump_format: Self::dump_format_from_matches(matches)?,
dump_format: matches
.get_one::<DumpFormat>(arg::DUMP_FORMAT)
.unwrap()
.clone(),
highlight: !matches.get_flag(arg::NO_HIGHLIGHT),
invocation_directory: env::current_dir().context(config_error::CurrentDirContext)?,
list_heading: matches

View File

@ -1,4 +1,4 @@
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone, clap::ValueEnum)]
pub(crate) enum DumpFormat {
Json,
Just,