eska_presentation/arguments/project/
metadata.rs1use crate::localization::Localizer;
4use clap::{Args, Subcommand, ValueEnum};
5use std::path::PathBuf;
6
7#[derive(Debug, Args)]
8pub struct MetadataArgs {
9 #[command(subcommand)]
10 pub command: MetadataCommand,
11 #[arg(short = 'p', long, global = true)]
12 pub project: Option<String>,
13 #[arg(long, global = true, value_enum, default_value_t = OutputFormat::Json)]
14 pub format: OutputFormat,
15 #[arg(short, long, action = clap::ArgAction::Help)]
16 pub help: Option<bool>,
17}
18
19#[derive(Clone, Copy, Debug, ValueEnum)]
20pub enum OutputFormat {
21 Json,
22}
23
24#[derive(Debug, Subcommand)]
25pub enum MetadataCommand {
26 #[command(disable_help_flag = true)]
27 Inspect(InspectArgs),
28 #[command(disable_help_flag = true)]
29 Types(InputArgs),
30 #[command(disable_help_flag = true)]
31 Choices(InputArgs),
32 #[command(disable_help_flag = true)]
33 Check(InputArgs),
34 #[command(disable_help_flag = true)]
35 Apply(InputArgs),
36 #[command(disable_help_flag = true)]
37 RenamePreview(InputArgs),
38 #[command(disable_help_flag = true)]
39 RenameApply(InputArgs),
40 #[command(disable_help_flag = true)]
41 RenameRecovery(InputArgs),
42}
43
44#[derive(Debug, Args)]
45pub struct InspectArgs {
46 #[arg(long)]
47 pub object: Option<String>,
48 #[arg(short, long, action = clap::ArgAction::Help)]
49 pub help: Option<bool>,
50}
51
52#[derive(Debug, Args)]
53pub struct InputArgs {
54 pub input: PathBuf,
55 #[arg(short, long, action = clap::ArgAction::Help)]
56 pub help: Option<bool>,
57}
58
59#[must_use]
61pub fn localize(mut command: clap::Command, locale: &Localizer) -> clap::Command {
62 command = command
63 .about(locale.text("metadata-about"))
64 .mut_arg("project", |arg| {
65 arg.help(locale.text("metadata-project-help"))
66 })
67 .mut_arg("format", |arg| {
68 arg.help(locale.text("metadata-format-help"))
69 })
70 .mut_arg("help", |arg| arg.help(locale.text("cli-help")));
71 for name in [
72 "inspect",
73 "types",
74 "choices",
75 "check",
76 "apply",
77 "rename-preview",
78 "rename-apply",
79 "rename-recovery",
80 ] {
81 command = command.mut_subcommand(name, |command| {
82 let command = command
83 .about(locale.text(&format!("metadata-{name}-about")))
84 .mut_arg("help", |arg| arg.help(locale.text("cli-help")));
85 if name == "inspect" {
86 command.mut_arg("object", |arg| {
87 arg.help(locale.text("metadata-object-help"))
88 })
89 } else {
90 command.mut_arg("input", |arg| arg.help(locale.text("metadata-input-help")))
91 }
92 });
93 }
94 command
95}