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("The \"{0}\" option must be provided for this command if more than one environment is defined.")]
44 OptionMissing(String),
45}
46
47#[derive(Debug, Parser)]
48#[command(name = BIN_NAME)]
49pub struct Cli {
50 #[arg(
51 env = "NETHSM_AUTH_PASSPHRASE_FILE",
52 global = true,
53 help = "The path to a file containing a passphrase for authentication",
54 long_help = "The path to a file containing a passphrase for authentication
55
56The passphrase provided in the file must be the one for the user chosen for the command.
57
58This option can be provided multiple times, which is needed for commands that require multiple roles at once.
59With multiple passphrase files ordering matters, as the files are assigned to the respective user provided by the \"--user\" option.",
60 long,
61 short
62 )]
63 pub auth_passphrase_file: Vec<PassphraseFile>,
64
65 #[arg(
66 env = "NETHSM_CONFIG",
67 global = true,
68 help = "The path to a custom configuration file",
69 long_help = "The path to a custom configuration file
70
71If specified, the custom configuration file is used instead of the default configuration file location.",
72 long,
73 short
74 )]
75 pub config: Option<PathBuf>,
76
77 #[arg(
78 env = "NETHSM_LABEL",
79 global = true,
80 help = "A label uniquely identifying a device in the configuration file",
81 long_help = "A label uniquely identifying a device in the configuration file
82
83Must be provided if more than one device is setup in the configuration file.",
84 long,
85 short
86 )]
87 pub label: Option<String>,
88
89 #[arg(
90 env = "NETHSM_USER",
91 global = true,
92 help = "A user name which is used for the command",
93 long_help = "A user name which is used for a command
94
95Can be provided, if no user name is setup in the configuration file for a device.
96Must be provided, if several user names of the same target role are setup in the configuration file for a device.
97
98This option can be provided multiple times, which is needed for commands that require multiple roles at once.
99",
100 long,
101 short
102 )]
103 pub user: Vec<UserId>,
104
105 #[command(subcommand)]
106 pub command: Command,
107}
108
109#[derive(Debug, Parser)]
110#[command(about, author, version)]
111pub enum Command {
112 #[command(subcommand)]
113 Config(ConfigCommand),
114
115 #[command(subcommand)]
116 Env(EnvCommand),
117
118 #[command(subcommand)]
119 Health(HealthCommand),
120
121 Info(InfoCommand),
122
123 #[command(subcommand)]
124 Key(KeyCommand),
125
126 Lock(LockCommand),
127
128 Metrics(MetricsCommand),
129
130 #[command(subcommand)]
131 Namespace(NamespaceCommand),
132
133 #[command(subcommand, name = "openpgp")]
134 OpenPgp(OpenPgpCommand),
135
136 Provision(ProvisionCommand),
137
138 Random(RandomCommand),
139
140 #[command(subcommand)]
141 System(SystemCommand),
142
143 Unlock(UnlockCommand),
144
145 #[command(subcommand)]
146 User(UserCommand),
147}