Skip to main content

auths_cli/
cli.rs

1use std::path::PathBuf;
2
3use clap::builder::styling::{AnsiColor, Effects, Styles};
4use clap::{Parser, Subcommand};
5
6use crate::commands::agent::AgentCommand;
7use crate::commands::artifact::ArtifactCommand;
8use crate::commands::audit::AuditCommand;
9use crate::commands::commit::CommitCmd;
10use crate::commands::completions::CompletionsCommand;
11use crate::commands::config::ConfigCommand;
12use crate::commands::debug::DebugCmd;
13use crate::commands::device::DeviceCommand;
14use crate::commands::doctor::DoctorCommand;
15use crate::commands::emergency::EmergencyCommand;
16use crate::commands::git::GitCommand;
17use crate::commands::id::IdCommand;
18use crate::commands::init::InitCommand;
19use crate::commands::key::KeyCommand;
20use crate::commands::learn::LearnCommand;
21use crate::commands::org::OrgCommand;
22use crate::commands::policy::PolicyCommand;
23use crate::commands::sign::SignCommand;
24use crate::commands::status::StatusCommand;
25use crate::commands::trust::TrustCommand;
26use crate::commands::unified_verify::UnifiedVerifyCommand;
27use crate::commands::witness::WitnessCommand;
28use crate::config::OutputFormat;
29
30fn cli_styles() -> Styles {
31    Styles::styled()
32        .header(AnsiColor::Green.on_default() | Effects::BOLD)
33        .usage(AnsiColor::Green.on_default() | Effects::BOLD)
34        .literal(AnsiColor::Cyan.on_default() | Effects::BOLD)
35        .placeholder(AnsiColor::Cyan.on_default())
36        .error(AnsiColor::Red.on_default() | Effects::BOLD)
37        .valid(AnsiColor::Green.on_default() | Effects::BOLD)
38        .invalid(AnsiColor::Yellow.on_default() | Effects::BOLD)
39}
40
41#[derive(Parser, Debug)]
42#[command(
43    name = "auths",
44    about = "auths \u{2014} cryptographic identity for developers",
45    long_about = "Commands:\n  init     Set up your cryptographic identity and Git signing\n  sign     Sign a Git commit or artifact\n  verify   Verify a signed commit or attestation\n  status   Show identity and signing status\n\nMore commands (run with --help for details):\n  auths device, auths id, auths key, auths policy, auths emergency, ...",
46    version,
47    styles = cli_styles()
48)]
49pub struct AuthsCli {
50    #[command(subcommand)]
51    pub command: RootCommand,
52
53    #[clap(
54        long,
55        value_enum,
56        default_value = "text",
57        global = true,
58        help_heading = "Display",
59        help = "Output format (text or json)"
60    )]
61    pub output: OutputFormat,
62
63    #[clap(
64        long,
65        global = true,
66        help_heading = "Display",
67        help = "Emit machine-readable JSON"
68    )]
69    pub json: bool,
70
71    #[clap(
72        short,
73        long,
74        global = true,
75        help_heading = "Display",
76        help = "Suppress non-essential output"
77    )]
78    pub quiet: bool,
79
80    #[clap(
81        long,
82        value_parser,
83        global = true,
84        help_heading = "Advanced Setup",
85        hide_short_help = true,
86        help = "Override the local storage directory (default: ~/.auths)"
87    )]
88    pub repo: Option<PathBuf>,
89}
90
91#[derive(Subcommand, Debug)]
92#[command(rename_all = "lowercase")]
93pub enum RootCommand {
94    Init(InitCommand),
95    Sign(SignCommand),
96    Verify(UnifiedVerifyCommand),
97    Status(StatusCommand),
98    Tutorial(LearnCommand),
99    Doctor(DoctorCommand),
100    Completions(CompletionsCommand),
101    Emergency(EmergencyCommand),
102
103    Id(IdCommand),
104    Device(DeviceCommand),
105    Key(KeyCommand),
106    Artifact(ArtifactCommand),
107    Policy(PolicyCommand),
108    Git(GitCommand),
109    Trust(TrustCommand),
110    Org(OrgCommand),
111    Audit(AuditCommand),
112    Agent(AgentCommand),
113    Witness(WitnessCommand),
114    Config(ConfigCommand),
115
116    #[command(hide = true)]
117    Commit(CommitCmd),
118    #[command(hide = true)]
119    Debug(DebugCmd),
120}