1use clap::{
5 Parser, Subcommand, ValueEnum,
6 builder::styling::{AnsiColor, Effects, Styles}
7};
8
9const HELP_STYLES: Styles = Styles::styled()
11 .header(AnsiColor::Yellow.on_default().effects(Effects::BOLD))
12 .usage(AnsiColor::Yellow.on_default().effects(Effects::BOLD))
13 .literal(AnsiColor::Cyan.on_default().effects(Effects::BOLD))
14 .placeholder(AnsiColor::Green.on_default())
15 .error(AnsiColor::Red.on_default().effects(Effects::BOLD))
16 .valid(AnsiColor::Green.on_default())
17 .invalid(AnsiColor::Red.on_default());
18
19mod apps;
20mod balancers;
21pub mod completers;
22mod databases;
23mod domains;
24mod firewall;
25mod images;
26mod kubernetes;
27mod network;
28mod projects;
29mod registry;
30mod s3;
31mod servers;
32mod settings;
33mod ssh;
34
35pub use apps::AppsCommands;
36pub use balancers::BalancerCommands;
37pub use databases::DatabaseCommands;
38pub use domains::DomainCommands;
39pub use firewall::FirewallCommands;
40pub use images::ImageCommands;
41pub use kubernetes::KubernetesCommands;
42pub use network::{IpCommands, VpcCommands};
43pub use projects::ProjectCommands;
44pub use registry::RegistryCommands;
45pub use s3::S3Commands;
46pub use servers::ServerCommands;
47pub use settings::{AccountCommands, AuthCommands, ConfigCommands};
48pub use ssh::SshCommands;
49
50#[derive(ValueEnum, Clone, Copy, Debug)]
52pub enum LangArg {
53 En,
55 Ru
57}
58
59#[derive(ValueEnum, Clone, Copy, Debug)]
61pub enum ShellArg {
62 Bash,
64 Zsh,
66 Fish,
68 Powershell,
70 Elvish,
72 Nushell
74}
75
76#[derive(Parser, Debug)]
78#[command(
79 name = "twc-rs",
80 version,
81 about = "Timeweb Cloud CLI — servers, databases, S3, Kubernetes, apps and more",
82 styles = HELP_STYLES
83)]
84pub struct Cli {
85 #[arg(
87 short,
88 long,
89 global = true,
90 default_value = "table",
91 env = "TWC_OUTPUT",
92 display_order = 900
93 )]
94 pub format: String,
95
96 #[arg(short, long, global = true, env = "TWC_TOKEN", display_order = 901)]
98 pub token: Option<String>,
99
100 #[arg(long, global = true, env = "TWC_PROFILE", display_order = 902)]
102 pub profile: Option<String>,
103
104 #[command(subcommand)]
105 pub command: Commands
106}
107
108#[derive(Subcommand, Debug)]
110pub enum Commands {
111 #[command(subcommand)]
113 Server(ServerCommands),
114
115 #[command(subcommand)]
117 Ssh(SshCommands),
118
119 #[command(subcommand)]
121 Project(ProjectCommands),
122
123 #[command(subcommand)]
125 Database(DatabaseCommands),
126
127 #[command(subcommand)]
129 S3(S3Commands),
130
131 #[command(subcommand)]
133 Kubernetes(KubernetesCommands),
134
135 #[command(subcommand)]
137 Registry(RegistryCommands),
138
139 #[command(subcommand)]
141 Balancer(BalancerCommands),
142
143 #[command(subcommand)]
145 Domain(DomainCommands),
146
147 #[command(subcommand)]
149 Firewall(FirewallCommands),
150
151 #[command(subcommand)]
153 Apps(AppsCommands),
154
155 #[command(subcommand)]
157 Image(ImageCommands),
158
159 #[command(subcommand)]
161 Ip(IpCommands),
162
163 #[command(subcommand)]
165 Vpc(VpcCommands),
166
167 #[command(subcommand)]
169 Account(AccountCommands),
170
171 #[command(subcommand)]
173 Config(ConfigCommands),
174
175 #[command(subcommand)]
177 Auth(AuthCommands),
178
179 Dashboard {
181 #[arg(short, long, default_value_t = 5)]
183 interval: u64
184 },
185
186 Completions {
188 #[arg(value_enum)]
190 shell: ShellArg
191 },
192
193 Doctor,
195
196 Update {
198 #[arg(long)]
200 check: bool
201 }
202}
203
204#[cfg(test)]
205mod tests;