Skip to main content

greentic_setup/
cli_args.rs

1//! CLI argument definitions for greentic-setup.
2
3use std::path::PathBuf;
4
5use clap::{Args, Parser, Subcommand};
6
7#[derive(Parser, Debug)]
8#[command(name = "greentic-setup")]
9#[command(version)]
10#[command(about = "Greentic bundle setup CLI")]
11#[command(after_help = r#"EXAMPLES:
12  Interactive wizard:
13    greentic-setup ./my-bundle
14
15  Preview without executing:
16    greentic-setup --dry-run ./my-bundle
17
18  Generate answers template:
19    greentic-setup --dry-run --emit-answers answers.json ./my-bundle
20
21  Apply answers file:
22    greentic-setup --answers answers.json ./my-bundle.gtbundle
23
24  Advanced (bundle subcommands):
25    greentic-setup bundle init ./my-bundle
26    greentic-setup bundle add pack.gtpack --bundle ./my-bundle
27    greentic-setup bundle status --bundle ./my-bundle
28"#)]
29pub struct Cli {
30    /// Bundle path (.gtbundle file or directory)
31    #[arg(value_name = "BUNDLE")]
32    pub bundle: Option<PathBuf>,
33
34    /// Dry run - show wizard but don't execute
35    #[arg(long = "dry-run", global = true)]
36    pub dry_run: bool,
37
38    /// Emit answers template to file (combine with --dry-run to only generate)
39    #[arg(long = "emit-answers", value_name = "FILE", global = true)]
40    pub emit_answers: Option<PathBuf>,
41
42    /// Apply answers from file
43    #[arg(long = "answers", short = 'a', value_name = "FILE", global = true)]
44    pub answers: Option<PathBuf>,
45
46    /// Encryption/decryption key for answer documents that include secrets
47    #[arg(long = "key", value_name = "KEY", global = true)]
48    pub key: Option<String>,
49
50    /// Tenant identifier
51    #[arg(long = "tenant", short = 't', default_value = "demo", global = true)]
52    pub tenant: String,
53
54    /// Team identifier
55    #[arg(long = "team", global = true)]
56    pub team: Option<String>,
57
58    /// Environment (dev/staging/prod)
59    #[arg(long = "env", short = 'e', default_value = "dev", global = true)]
60    pub env: String,
61
62    /// UI locale (BCP-47 tag, e.g., en, ja, id)
63    #[arg(long = "locale", global = true)]
64    pub locale: Option<String>,
65
66    /// Advanced mode — show all questions including optional ones
67    #[arg(long = "advanced", global = true)]
68    pub advanced: bool,
69
70    #[command(subcommand)]
71    pub command: Option<Command>,
72}
73
74#[derive(Subcommand, Debug)]
75pub enum Command {
76    /// Bundle lifecycle management (advanced)
77    #[command(subcommand)]
78    Bundle(BundleCommand),
79}
80
81#[derive(Subcommand, Debug, Clone)]
82pub enum BundleCommand {
83    /// Initialize a new bundle directory
84    Init(BundleInitArgs),
85    /// Add a pack to a bundle
86    Add(BundleAddArgs),
87    /// Run setup flow for provider(s) in a bundle
88    Setup(BundleSetupArgs),
89    /// Update a provider's configuration in a bundle
90    Update(BundleSetupArgs),
91    /// Remove a provider from a bundle
92    Remove(BundleRemoveArgs),
93    /// Build a portable bundle (copy + resolve)
94    Build(BundleBuildArgs),
95    /// List packs or flows in a bundle
96    List(BundleListArgs),
97    /// Show bundle status
98    Status(BundleStatusArgs),
99}
100
101#[derive(Args, Debug, Clone)]
102pub struct BundleInitArgs {
103    /// Bundle directory (default: current directory)
104    #[arg(value_name = "PATH")]
105    pub path: Option<PathBuf>,
106    /// Bundle name
107    #[arg(long = "name", short = 'n')]
108    pub name: Option<String>,
109}
110
111#[derive(Args, Debug, Clone)]
112pub struct BundleAddArgs {
113    /// Pack reference (local path or OCI reference)
114    #[arg(value_name = "PACK_REF")]
115    pub pack_ref: String,
116    /// Bundle directory (default: current directory)
117    #[arg(long = "bundle", short = 'b')]
118    pub bundle: Option<PathBuf>,
119    /// Tenant identifier
120    #[arg(long = "tenant", short = 't', default_value = "demo")]
121    pub tenant: String,
122    /// Team identifier
123    #[arg(long = "team")]
124    pub team: Option<String>,
125    /// Environment (dev/staging/prod)
126    #[arg(long = "env", short = 'e', default_value = "dev")]
127    pub env: String,
128    /// Dry run (don't actually add)
129    #[arg(long = "dry-run")]
130    pub dry_run: bool,
131}
132
133#[derive(Args, Debug, Clone)]
134pub struct BundleSetupArgs {
135    /// Provider ID to setup/update (optional, setup all if not specified)
136    #[arg(value_name = "PROVIDER_ID")]
137    pub provider_id: Option<String>,
138    /// Bundle directory (default: current directory)
139    #[arg(long = "bundle", short = 'b')]
140    pub bundle: Option<PathBuf>,
141    /// Answers file (JSON/YAML)
142    #[arg(long = "answers", short = 'a')]
143    pub answers: Option<PathBuf>,
144    /// Encryption/decryption key for answer documents that include secrets
145    #[arg(long = "key", value_name = "KEY")]
146    pub key: Option<String>,
147    /// Tenant identifier
148    #[arg(long = "tenant", short = 't', default_value = "demo")]
149    pub tenant: String,
150    /// Team identifier
151    #[arg(long = "team")]
152    pub team: Option<String>,
153    /// Environment (dev/staging/prod)
154    #[arg(long = "env", short = 'e', default_value = "dev")]
155    pub env: String,
156    /// Filter by domain (messaging/events/secrets/oauth/all)
157    #[arg(long = "domain", short = 'd', default_value = "all")]
158    pub domain: String,
159    /// Number of parallel setup operations
160    #[arg(long = "parallel", default_value = "1")]
161    pub parallel: usize,
162    /// Backup existing config before setup
163    #[arg(long = "backup")]
164    pub backup: bool,
165    /// Skip secrets initialization
166    #[arg(long = "skip-secrets-init")]
167    pub skip_secrets_init: bool,
168    /// Continue on error (best effort)
169    #[arg(long = "best-effort")]
170    pub best_effort: bool,
171    /// Non-interactive mode (require --answers)
172    #[arg(long = "non-interactive")]
173    pub non_interactive: bool,
174    /// Dry run (plan only, don't execute)
175    #[arg(long = "dry-run")]
176    pub dry_run: bool,
177    /// Emit answers template JSON (use with --dry-run)
178    #[arg(long = "emit-answers")]
179    pub emit_answers: Option<PathBuf>,
180    /// Advanced mode — show all questions including optional ones
181    #[arg(long = "advanced")]
182    pub advanced: bool,
183}
184
185#[derive(Args, Debug, Clone)]
186pub struct BundleRemoveArgs {
187    /// Provider ID to remove
188    #[arg(value_name = "PROVIDER_ID")]
189    pub provider_id: String,
190    /// Bundle directory (default: current directory)
191    #[arg(long = "bundle", short = 'b')]
192    pub bundle: Option<PathBuf>,
193    /// Tenant identifier
194    #[arg(long = "tenant", short = 't', default_value = "demo")]
195    pub tenant: String,
196    /// Team identifier
197    #[arg(long = "team")]
198    pub team: Option<String>,
199    /// Force removal without confirmation
200    #[arg(long = "force", short = 'f')]
201    pub force: bool,
202}
203
204#[derive(Args, Debug, Clone)]
205pub struct BundleBuildArgs {
206    /// Bundle directory (default: current directory)
207    #[arg(long = "bundle", short = 'b')]
208    pub bundle: Option<PathBuf>,
209    /// Output directory for portable bundle
210    #[arg(long = "out", short = 'o')]
211    pub out: PathBuf,
212    /// Tenant identifier
213    #[arg(long = "tenant", short = 't')]
214    pub tenant: Option<String>,
215    /// Team identifier
216    #[arg(long = "team")]
217    pub team: Option<String>,
218    /// Only include used providers
219    #[arg(long = "only-used-providers")]
220    pub only_used_providers: bool,
221    /// Run doctor validation after build
222    #[arg(long = "doctor")]
223    pub doctor: bool,
224    /// Skip doctor validation
225    #[arg(long = "skip-doctor")]
226    pub skip_doctor: bool,
227}
228
229#[derive(Args, Debug, Clone)]
230pub struct BundleListArgs {
231    /// Bundle directory (default: current directory)
232    #[arg(long = "bundle", short = 'b')]
233    pub bundle: Option<PathBuf>,
234    /// Filter by domain (messaging/events/secrets/oauth)
235    #[arg(long = "domain", short = 'd', default_value = "messaging")]
236    pub domain: String,
237    /// Show flows for a specific pack
238    #[arg(long = "pack", short = 'p')]
239    pub pack: Option<String>,
240    /// Output format (text/json)
241    #[arg(long = "format", default_value = "text")]
242    pub format: String,
243}
244
245#[derive(Args, Debug, Clone)]
246pub struct BundleStatusArgs {
247    /// Bundle directory (default: current directory)
248    #[arg(long = "bundle", short = 'b')]
249    pub bundle: Option<PathBuf>,
250    /// Output format (text/json)
251    #[arg(long = "format", default_value = "text")]
252    pub format: String,
253}