gl_env/cli.rs
1//! Definition of the command-line interfaces.
2//!
3//! Doc-comments in this file will likely show up in a help text.
4
5use clap::{Args, Parser, Subcommand};
6use url::Url;
7
8/// Tools to bulk-edit Project-level CI/CD variables in GitLab.
9#[derive(Parser)]
10#[command(version, about, long_about = None)]
11pub struct Cli {
12 #[command(subcommand)]
13 pub command: Commands,
14}
15
16#[derive(Subcommand)]
17pub enum Commands {
18 /// List all configured CI/CD variables
19 ///
20 /// Output columns: Key, Environment, Masked, Protected, Raw
21 List(CommonArgs),
22
23 /// Show a diff between actual and desired variables
24 Diff(CommonArgs),
25
26 /// Dump the current variables
27 Dump(CommonArgs),
28
29 /// Apply desired variables
30 Apply {
31 #[clap(flatten)]
32 args: CommonArgs,
33
34 /// Print what WOULD been done, but don't actually do it
35 #[arg(short, long)]
36 dry_run: bool,
37
38 /// Remove variables not present in desired state
39 #[arg(long)]
40 prune: bool,
41 },
42}
43
44/// Arguments shared between all commands
45#[derive(Args)]
46pub struct CommonArgs {
47 /// Base URL of the GitLab instance.
48 #[arg(
49 short,
50 long,
51 default_value = "https://gitlab.com",
52 global = true,
53 env = "GITLAB_URL"
54 )]
55 pub url: Url,
56
57 /// Personal Access Token.
58 ///
59 /// Required scopes: `api`.
60 #[arg(short, long, env = "GITLAB_TOKEN", hide_env_values = true)]
61 pub token: String,
62
63 /// Path/ID of the project (either `mygroup/myproject` or numeric Project ID).
64 #[arg(short, long)]
65 pub project: Option<String>,
66
67 /// Path/ID of the group (either `mygroup` or numeric Group ID).
68 #[arg(short, long)]
69 pub group: Option<String>,
70}