Skip to main content

nethsm/cli/command/
mod.rs

1//! Command line handling for the "nethsm" executable.
2
3mod config;
4mod env;
5mod health;
6mod info;
7mod key;
8mod lock;
9mod metrics;
10mod namespace;
11mod openpgp;
12mod provision;
13mod random;
14mod system;
15mod unlock;
16mod user;
17
18use std::path::PathBuf;
19
20use clap::Parser;
21pub use config::{ConfigCommand, ConfigGetCommand, ConfigSetCommand};
22pub use env::{EnvAddCommand, EnvCommand, EnvDeleteCommand};
23pub use health::HealthCommand;
24pub use info::InfoCommand;
25pub use key::{KeyCertCommand, KeyCommand};
26pub use lock::LockCommand;
27pub use metrics::MetricsCommand;
28pub use namespace::NamespaceCommand;
29pub use openpgp::OpenPgpCommand;
30pub use provision::ProvisionCommand;
31pub use random::RandomCommand;
32pub use system::SystemCommand;
33pub use unlock::UnlockCommand;
34pub use user::UserCommand;
35
36use crate::{UserId, cli::PassphraseFile};
37
38/// The name of the executable.
39const BIN_NAME: &str = env!("CARGO_PKG_NAME");
40
41/// The "nethsm" CLI.
42#[derive(Debug, Parser)]
43#[command(name = BIN_NAME)]
44pub struct Cli {
45    /// Passphrase file(s).
46    #[arg(
47        env = "NETHSM_AUTH_PASSPHRASE_FILE",
48        global = true,
49        help = "The path to a file containing a passphrase for authentication",
50        long_help = "The path to a file containing a passphrase for authentication
51
52The passphrase provided in the file must be the one for the user chosen for the command.
53
54This option can be provided multiple times, which is needed for commands that require multiple roles at once.
55With multiple passphrase files ordering matters, as the files are assigned to the respective user provided by the \"--user\" option.",
56        long,
57        short
58    )]
59    pub auth_passphrase_file: Vec<PassphraseFile>,
60
61    /// An optional config file to use.
62    #[arg(
63        env = "NETHSM_CONFIG",
64        global = true,
65        help = "The path to a custom configuration file",
66        long_help = "The path to a custom configuration file
67
68If specified, the custom configuration file is used instead of the default configuration file location.",
69        long,
70        short
71    )]
72    pub config: Option<PathBuf>,
73
74    /// An optional label to use for a NetHSM backend.
75    #[arg(
76        env = "NETHSM_LABEL",
77        global = true,
78        help = "A label uniquely identifying a device in the configuration file",
79        long_help = "A label uniquely identifying a device in the configuration file
80
81Must be provided if more than one device is setup in the configuration file.",
82        long,
83        short
84    )]
85    pub label: Option<String>,
86
87    /// A user ID to use with a NetHSM backend.
88    #[arg(
89        env = "NETHSM_USER",
90        global = true,
91        help = "A user name which is used for the command",
92        long_help = "A user name which is used for a command
93
94Can be provided, if no user name is setup in the configuration file for a device.
95Must be provided, if several user names of the same target role are setup in the configuration file for a device.
96
97This option can be provided multiple times, which is needed for commands that require multiple roles at once.
98",
99        long,
100        short
101    )]
102    pub user: Vec<UserId>,
103
104    /// A "nethsm" subcommand.
105    #[command(subcommand)]
106    pub command: Command,
107}
108
109/// The "nethsm" CLI commands.
110#[derive(Debug, Parser)]
111#[command(about, author, version)]
112pub enum Command {
113    /// The "nethsm config" command.
114    #[command(subcommand)]
115    Config(ConfigCommand),
116
117    /// The "nethsm env" command.
118    #[command(subcommand)]
119    Env(EnvCommand),
120
121    /// The "nethsm health" command.
122    #[command(subcommand)]
123    Health(HealthCommand),
124
125    /// The "nethsm info" command.
126    Info(InfoCommand),
127
128    /// The "nethsm key" command.
129    #[command(subcommand)]
130    Key(KeyCommand),
131
132    /// The "nethsm lock" command.
133    Lock(LockCommand),
134
135    /// The "nethsm metrics" command.
136    Metrics(MetricsCommand),
137
138    /// The "nethsm namespace" command.
139    #[command(subcommand)]
140    Namespace(NamespaceCommand),
141
142    /// The "nethsm openpgp" command.
143    #[command(subcommand, name = "openpgp")]
144    OpenPgp(OpenPgpCommand),
145
146    /// The "nethsm provision" command.
147    Provision(ProvisionCommand),
148
149    /// The "nethsm random" command.
150    Random(RandomCommand),
151
152    /// The "nethsm system" command.
153    #[command(subcommand)]
154    System(SystemCommand),
155
156    /// The "nethsm unlock" command.
157    Unlock(UnlockCommand),
158
159    /// The "nethsm user" command.
160    #[command(subcommand)]
161    User(UserCommand),
162}