From afebea6e730e853ecefb856d1c850612f146c93c Mon Sep 17 00:00:00 2001 From: Aleksey Kuznetsov Date: Sat, 10 Feb 2024 11:01:47 +0500 Subject: [PATCH] cli: make `jj show` accept a template to render its output --- CHANGELOG.md | 3 +++ cli/src/commands/show.rs | 10 +++++++++- cli/tests/cli-reference@.md.snap | 1 + cli/tests/test_show_command.rs | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcf54f08e..f2555c988 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Templates now support logical operators: `||`, `&&`, `!` +* `jj show` now accepts `-T`/`--template` option to render its output using + template + ### Fixed bugs * On Windows, symlinks in the repo are now materialized as regular files in the diff --git a/cli/src/commands/show.rs b/cli/src/commands/show.rs index 7afcccb44..4529654ce 100644 --- a/cli/src/commands/show.rs +++ b/cli/src/commands/show.rs @@ -28,6 +28,11 @@ pub(crate) struct ShowArgs { /// Ignored (but lets you pass `-r` for consistency with other commands) #[arg(short = 'r', hide = true)] unused_revision: bool, + /// Render a revision using the given template + /// + /// For the syntax, see https://github.com/martinvonz/jj/blob/main/docs/templates.md + #[arg(long, short = 'T')] + template: Option, #[command(flatten)] format: DiffFormatArgs, } @@ -40,7 +45,10 @@ pub(crate) fn cmd_show( ) -> Result<(), CommandError> { let workspace_command = command.workspace_helper(ui)?; let commit = workspace_command.resolve_single_rev(&args.revision, ui)?; - let template_string = command.settings().config().get_string("templates.show")?; + let template_string = match &args.template { + Some(value) => value.to_string(), + None => command.settings().config().get_string("templates.show")?, + }; let template = workspace_command.parse_commit_template(&template_string)?; let diff_formats = diff_util::diff_formats_for(command.settings(), &args.format)?; ui.request_pager(); diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index 8e893c4cf..afe065422 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -1551,6 +1551,7 @@ Show commit description and changes in a revision Possible values: `true`, `false` +* `-T`, `--template