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