-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli: improve discoverability of template-aliases #3189
Conversation
This looks useful at first glance. |
I'm not sure about the file name but one can explore a template using
Currently, there is no connection between templates and their corresponding commands. For instance, using
|
When user types `jj log -T` without passing a template name we can list all of them
5b33309
to
ff4d0c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems useful.
builtin_change_id_with_hidden_and_divergent_info
builtin_log_comfortable
builtin_log_compact
builtin_log_detailed
builtin_log_oneline
builtin_op_log_comfortable
builtin_op_log_compact
commit_summary_separator
description_placeholder
email_placeholder
name_placeholder
Not all aliases are supposed to be used as a top-level template, but I have no idea how we can improve that. We could use a static list of builtin templates, but that means user aliases wouldn't be included.
for name in template_names { | ||
hint.push('\n'); | ||
hint.push_str(padding); | ||
hint.push_str(name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: something like writeln!(hint, " {name}").unwrap()
also works. Or simply .map(|name| format!(..)).join("\n")
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format!
will allocate a new string. It's not that important here of course, but still... I think writeln!(hint, " {name}").unwrap()
will be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. It's not important here, but clippy might complain about that.
@@ -561,6 +561,10 @@ impl TemplateAliasesMap { | |||
Self::default() | |||
} | |||
|
|||
pub fn symbol_aliases_keys(&self) -> Vec<&str> { | |||
self.symbol_aliases.keys().map(|s| s.as_str()).collect_vec() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: simply return impl Iterator<Item = &str>
as the caller need to post-process the items anyway?
@@ -561,6 +561,10 @@ impl TemplateAliasesMap { | |||
Self::default() | |||
} | |||
|
|||
pub fn symbol_aliases_keys(&self) -> Vec<&str> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: symbol_names
or symbol_alias_names
("key" sounds more like an implementation detail.)
@@ -179,7 +179,7 @@ fn test_log_with_or_without_diff() { | |||
insta::assert_snapshot!(stderr, @r###" | |||
error: the argument '--git' cannot be used with '--color-words' | |||
|
|||
Usage: jj log --template <TEMPLATE> --no-graph --patch --git [PATHS]... | |||
Usage: jj log --template [<TEMPLATE>] --no-graph --patch --git [PATHS]... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unfortunate that the --template
value has to be optional.
Another implementation idea is to inspect the clap::Error
at handle_command_result()
or CliRunner::run_internal()
.
[cli/src/command_error.rs:478:13] (inner.kind(), inner.context().collect_vec()) = (
InvalidValue,
[
(
InvalidArg,
String(
"--template <TEMPLATE>",
),
),
(
InvalidValue,
String(
"",
),
),
(
ValidValue,
Strings(
[],
),
),
],
)
Doing that seems intrusive, but I think it's okay because --template
is the concept apply to many commands. A downside is that we'll need to build template aliases from the config object available at that point (because WorkspaceCommandHelper
isn't instantiated yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've implemented this variant in #3200. Please take a look.
Yeah, I think it's important to include user templates in the output. On improvement: I was thinking maybe we could have some kind of introspection for templates to extract "features" and match these set of "features" with the set of "features" of a command. In my opinion, this greatly overcomplicate things and maybe not worth it in this context. |
Closing in favor of #3200 |
This is follow up of #3175. This is a draft. Looking for initial feedback.
When user types
jj log -T
without passing a template name we can list all of them:Checklist
If applicable:
CHANGELOG.md