Skip to main content

eska_presentation/arguments/vcs/
diff.rs

1//! Shared VCS argument metadata; repository execution stays in its process owner.
2
3use crate::localization::Localizer;
4use clap::{Args, ValueEnum};
5
6#[derive(Debug, Args)]
7pub struct DiffArgs {
8    #[arg(value_name = "REVISION", num_args = 0..=2)]
9    pub revisions: Vec<String>,
10
11    #[arg(long, requires = "revisions")]
12    pub since_branch_point: bool,
13
14    #[arg(long, conflicts_with = "format")]
15    pub raw: bool,
16
17    #[arg(long)]
18    pub semantic: bool,
19
20    #[arg(long, value_enum, default_value_t = OutputFormat::Human)]
21    pub format: OutputFormat,
22
23    #[command(flatten)]
24    pub selectors: DiffSelectors,
25
26    #[arg(short, long, action = clap::ArgAction::Help)]
27    pub help: Option<bool>,
28}
29
30#[derive(Debug, Args)]
31pub struct DiffSelectors {
32    #[arg(short = 'p', long)]
33    pub project: Vec<String>,
34
35    #[arg(long)]
36    pub workspace: bool,
37}
38
39#[derive(Clone, Copy, Debug, Default, ValueEnum)]
40pub enum OutputFormat {
41    #[default]
42    Human,
43    Json,
44}
45
46/// Apply localized help text after clap has parsed the bootstrap locale.
47#[must_use]
48pub fn localize(command: clap::Command, localizer: &Localizer) -> clap::Command {
49    command
50        .about(localizer.text("diff-about"))
51        .override_usage(localizer.text("diff-usage"))
52        .mut_arg("revisions", |argument| {
53            argument
54                .help(localizer.text("diff-revisions-help"))
55                .value_name(localizer.text("diff-revisions-value"))
56        })
57        .mut_arg("since_branch_point", |argument| {
58            argument.help(localizer.text("diff-since-branch-point-help"))
59        })
60        .mut_arg("raw", |argument| {
61            argument.help(localizer.text("diff-raw-help"))
62        })
63        .mut_arg("semantic", |argument| {
64            argument.help(localizer.text("diff-semantic-help"))
65        })
66        .mut_arg("format", |argument| {
67            argument
68                .help(localizer.text("diff-format-help"))
69                .value_name(localizer.text("diff-format-value"))
70        })
71        .mut_arg("project", |argument| {
72            argument
73                .help(localizer.text("diff-project-help"))
74                .value_name(localizer.text("diff-project-value"))
75        })
76        .mut_arg("workspace", |argument| {
77            argument.help(localizer.text("diff-workspace-help"))
78        })
79        .mut_arg("help", |argument| argument.help(localizer.text("cli-help")))
80}