diff --git a/CHANGELOG.md b/CHANGELOG.md index fe6699841..f1bd4baf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Commands producing diffs now accept a `--context` flag for the number of lines of context to show. +* `jj` commands with the `-T`/`--template` option now provide a hint containing + defined template names when no argument is given, assisting the user in making + a selection. + ### Fixed bugs * On Windows, symlinks in the repo are now supported when Developer Mode is enabled. diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index ea6de9183..6938a2882 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -28,6 +28,7 @@ use std::time::SystemTime; use std::{fs, str}; use clap::builder::{NonEmptyStringValueParser, TypedValueParser, ValueParserFactory}; +use clap::error::{ContextKind, ContextValue}; use clap::{Arg, ArgAction, ArgMatches, Command, FromArgMatches}; use indexmap::{IndexMap, IndexSet}; use itertools::Itertools; @@ -2525,7 +2526,8 @@ impl CliRunner { &self.tracing_subscription, &string_args, &mut layered_configs, - )?; + ) + .map_err(|err| map_clap_cli_error(err, ui, &layered_configs))?; for process_global_args_fn in self.process_global_args_fns { process_global_args_fn(ui, &matches)?; } @@ -2599,3 +2601,40 @@ impl CliRunner { exit_code } } + +fn map_clap_cli_error( + cmd_err: CommandError, + ui: &Ui, + layered_configs: &LayeredConfigs, +) -> CommandError { + let CommandError::ClapCliError { err, hint: None } = &cmd_err else { + return cmd_err; + }; + if let (Some(ContextValue::String(arg)), Some(ContextValue::String(value))) = ( + err.get(ContextKind::InvalidArg), + err.get(ContextKind::InvalidValue), + ) { + if arg.as_str() == "--template