Skip to main content

eska_presentation/arguments/build/
platform.rs

1//! Shared native command options and help; execution belongs to eska-build.
2
3use crate::localization::Localizer;
4use clap::{Args, Subcommand, ValueEnum};
5use std::path::PathBuf;
6
7#[derive(Debug, Args)]
8pub struct PlatformArgs {
9    #[command(subcommand)]
10    pub command: PlatformCommand,
11
12    #[arg(short, long, action = clap::ArgAction::Help)]
13    pub help: Option<bool>,
14}
15
16#[derive(Debug, Subcommand)]
17pub enum PlatformCommand {
18    #[command(disable_help_flag = true)]
19    List(PlatformListArgs),
20}
21
22#[derive(Debug, Args)]
23pub struct PlatformListArgs {
24    #[arg(long)]
25    pub ibcmd: Option<PathBuf>,
26
27    #[arg(long)]
28    pub platform_arch: Option<String>,
29
30    #[arg(long)]
31    pub distrobox: Option<String>,
32
33    #[arg(long, value_enum, default_value_t = PlatformOutputFormat::Human)]
34    pub format: PlatformOutputFormat,
35
36    #[arg(short, long, action = clap::ArgAction::Help)]
37    pub help: Option<bool>,
38}
39
40#[derive(Clone, Copy, Debug, Default, ValueEnum)]
41pub enum PlatformOutputFormat {
42    #[default]
43    Human,
44    Json,
45}
46
47/// Localize native options without invoking the runtime owner.
48pub fn localize(command: clap::Command, localizer: &Localizer) -> clap::Command {
49    command
50        .about(localizer.text("platform-about"))
51        .override_usage(localizer.text("platform-usage"))
52        .mut_arg("help", |argument| argument.help(localizer.text("cli-help")))
53        .mut_subcommand("list", |command| {
54            command
55                .about(localizer.text("platform-list-about"))
56                .override_usage(localizer.text("platform-list-usage"))
57                .mut_arg("ibcmd", |arg| {
58                    arg.help(localizer.text("build-ibcmd-help"))
59                        .value_name(localizer.text("build-ibcmd-value"))
60                })
61                .mut_arg("platform_arch", |arg| {
62                    arg.help(localizer.text("build-arch-help"))
63                        .value_name(localizer.text("build-arch-value"))
64                })
65                .mut_arg("distrobox", |arg| {
66                    arg.help(localizer.text("build-distrobox-help"))
67                        .value_name(localizer.text("build-distrobox-value"))
68                })
69                .mut_arg("format", |arg| {
70                    arg.help(localizer.text("build-format-help"))
71                        .value_name(localizer.text("build-format-value"))
72                })
73                .mut_arg("help", |argument| argument.help(localizer.text("cli-help")))
74        })
75}