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