mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-07 05:16:33 +00:00
cli: migrate "tag list" to template
I'm going to add more detailed output there. This is a step towards "branch list" template. "tag list -T" wouldn't be that useful, but it shares primitives with "branch list -T".
This commit is contained in:
parent
d1458b55d2
commit
1ce3e9fe44
4 changed files with 39 additions and 5 deletions
|
@ -16,6 +16,7 @@ use jj_lib::str_util::StringPattern;
|
|||
|
||||
use crate::cli_util::CommandHelper;
|
||||
use crate::command_error::CommandError;
|
||||
use crate::commit_templater::{CommitTemplateLanguage, RefName};
|
||||
use crate::ui::Ui;
|
||||
|
||||
/// Manage tags.
|
||||
|
@ -35,6 +36,13 @@ pub struct TagListArgs {
|
|||
/// https://github.com/martinvonz/jj/blob/main/docs/revsets.md#string-patterns.
|
||||
#[arg(value_parser = StringPattern::parse)]
|
||||
pub names: Vec<StringPattern>,
|
||||
/// Render each tag using the given template
|
||||
///
|
||||
/// All 0-argument methods of the `RefName` type are available as keywords.
|
||||
///
|
||||
/// For the syntax, see https://github.com/martinvonz/jj/blob/main/docs/templates.md
|
||||
#[arg(long, short = 'T')]
|
||||
template: Option<String>,
|
||||
}
|
||||
|
||||
pub fn cmd_tag(
|
||||
|
@ -56,16 +64,26 @@ fn cmd_tag_list(
|
|||
let repo = workspace_command.repo();
|
||||
let view = repo.view();
|
||||
|
||||
let template = {
|
||||
let language = workspace_command.commit_template_language()?;
|
||||
let text = match &args.template {
|
||||
Some(value) => value.to_owned(),
|
||||
None => command.settings().config().get("templates.tag_list")?,
|
||||
};
|
||||
workspace_command
|
||||
.parse_template(&language, &text, CommitTemplateLanguage::wrap_ref_name)?
|
||||
.labeled("tag_list")
|
||||
};
|
||||
|
||||
ui.request_pager();
|
||||
let mut formatter = ui.stdout_formatter();
|
||||
let formatter = formatter.as_mut();
|
||||
|
||||
for name in view.tags().keys() {
|
||||
for (name, target) in view.tags() {
|
||||
if !args.names.is_empty() && !args.names.iter().any(|pattern| pattern.matches(name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
writeln!(formatter.labeled("tag"), "{name}")?;
|
||||
let ref_name = RefName::local_only(name, target.clone());
|
||||
template.format(&ref_name, formatter.as_mut())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -17,6 +17,10 @@ log = 'builtin_log_compact'
|
|||
op_log = 'builtin_op_log_compact'
|
||||
show = 'builtin_log_detailed'
|
||||
|
||||
tag_list = '''
|
||||
label("tag", name) ++ "\n"
|
||||
'''
|
||||
|
||||
[template-aliases]
|
||||
builtin_log_oneline = '''
|
||||
if(root,
|
||||
|
|
|
@ -1824,12 +1824,16 @@ Manage tags
|
|||
|
||||
List tags
|
||||
|
||||
**Usage:** `jj tag list [NAMES]...`
|
||||
**Usage:** `jj tag list [OPTIONS] [NAMES]...`
|
||||
|
||||
###### **Arguments:**
|
||||
|
||||
* `<NAMES>` — Show tags whose local name matches
|
||||
|
||||
###### **Options:**
|
||||
|
||||
* `-T`, `--template <TEMPLATE>` — Render each tag using the given template
|
||||
|
||||
|
||||
|
||||
## `jj util`
|
||||
|
|
|
@ -60,4 +60,12 @@ fn test_tag_list() {
|
|||
@r###"
|
||||
test_tag2
|
||||
"###);
|
||||
|
||||
let template = r#"'name: ' ++ name ++ "\n""#;
|
||||
insta::assert_snapshot!(
|
||||
test_env.jj_cmd_success(&repo_path, &["tag", "list", "-T", template]),
|
||||
@r###"
|
||||
name: test_tag
|
||||
name: test_tag2
|
||||
"###);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue