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    /// Launch web-based setup UI in browser
71    #[arg(long = "ui", global = true)]
72    pub ui: bool,
73
74    #[command(subcommand)]
75    pub command: Option<Command>,
76}
77
78#[derive(Subcommand, Debug)]
79pub enum Command {
80    /// Bundle lifecycle management (advanced)
81    #[command(subcommand)]
82    Bundle(BundleCommand),
83}
84
85#[derive(Subcommand, Debug, Clone)]
86pub enum BundleCommand {
87    /// Initialize a new bundle directory
88    Init(BundleInitArgs),
89    /// Add a pack to a bundle
90    Add(BundleAddArgs),
91    /// Run setup flow for provider(s) in a bundle
92    Setup(BundleSetupArgs),
93    /// Update a provider's configuration in a bundle
94    Update(BundleSetupArgs),
95    /// Remove a provider from a bundle
96    Remove(BundleRemoveArgs),
97    /// Build a portable bundle (copy + resolve)
98    Build(BundleBuildArgs),
99    /// List packs or flows in a bundle
100    List(BundleListArgs),
101    /// Show bundle status
102    Status(BundleStatusArgs),
103}
104
105#[derive(Args, Debug, Clone)]
106pub struct BundleInitArgs {
107    /// Bundle directory (default: current directory)
108    #[arg(value_name = "PATH")]
109    pub path: Option<PathBuf>,
110    /// Bundle name
111    #[arg(long = "name", short = 'n')]
112    pub name: Option<String>,
113}
114
115#[derive(Args, Debug, Clone)]
116pub struct BundleAddArgs {
117    /// Pack reference (local path or OCI reference)
118    #[arg(value_name = "PACK_REF")]
119    pub pack_ref: String,
120    /// Bundle directory (default: current directory)
121    #[arg(long = "bundle", short = 'b')]
122    pub bundle: Option<PathBuf>,
123    /// Tenant identifier
124    #[arg(long = "tenant", short = 't', default_value = "demo")]
125    pub tenant: String,
126    /// Team identifier
127    #[arg(long = "team")]
128    pub team: Option<String>,
129    /// Environment (dev/staging/prod)
130    #[arg(long = "env", short = 'e', default_value = "dev")]
131    pub env: String,
132    /// Dry run (don't actually add)
133    #[arg(long = "dry-run")]
134    pub dry_run: bool,
135}
136
137#[derive(Args, Debug, Clone)]
138pub struct BundleSetupArgs {
139    /// Provider ID to setup/update (optional, setup all if not specified)
140    #[arg(value_name = "PROVIDER_ID")]
141    pub provider_id: Option<String>,
142    /// Bundle directory (default: current directory)
143    #[arg(long = "bundle", short = 'b')]
144    pub bundle: Option<PathBuf>,
145    /// Answers file (JSON/YAML)
146    #[arg(long = "answers", short = 'a')]
147    pub answers: Option<PathBuf>,
148    /// Encryption/decryption key for answer documents that include secrets
149    #[arg(long = "key", value_name = "KEY")]
150    pub key: Option<String>,
151    /// Tenant identifier
152    #[arg(long = "tenant", short = 't', default_value = "demo")]
153    pub tenant: String,
154    /// Team identifier
155    #[arg(long = "team")]
156    pub team: Option<String>,
157    /// Environment (dev/staging/prod)
158    #[arg(long = "env", short = 'e', default_value = "dev")]
159    pub env: String,
160    /// Filter by domain (messaging/events/secrets/oauth/all)
161    #[arg(long = "domain", short = 'd', default_value = "all")]
162    pub domain: String,
163    /// Number of parallel setup operations
164    #[arg(long = "parallel", default_value = "1")]
165    pub parallel: usize,
166    /// Backup existing config before setup
167    #[arg(long = "backup")]
168    pub backup: bool,
169    /// Skip secrets initialization
170    #[arg(long = "skip-secrets-init")]
171    pub skip_secrets_init: bool,
172    /// Continue on error (best effort)
173    #[arg(long = "best-effort")]
174    pub best_effort: bool,
175    /// Non-interactive mode (require --answers)
176    #[arg(long = "non-interactive")]
177    pub non_interactive: bool,
178    /// Dry run (plan only, don't execute)
179    #[arg(long = "dry-run")]
180    pub dry_run: bool,
181    /// Emit answers template JSON (use with --dry-run)
182    #[arg(long = "emit-answers")]
183    pub emit_answers: Option<PathBuf>,
184    /// Advanced mode — show all questions including optional ones
185    #[arg(long = "advanced")]
186    pub advanced: bool,
187}
188
189#[derive(Args, Debug, Clone)]
190pub struct BundleRemoveArgs {
191    /// Provider ID to remove
192    #[arg(value_name = "PROVIDER_ID")]
193    pub provider_id: String,
194    /// Bundle directory (default: current directory)
195    #[arg(long = "bundle", short = 'b')]
196    pub bundle: Option<PathBuf>,
197    /// Tenant identifier
198    #[arg(long = "tenant", short = 't', default_value = "demo")]
199    pub tenant: String,
200    /// Team identifier
201    #[arg(long = "team")]
202    pub team: Option<String>,
203    /// Force removal without confirmation
204    #[arg(long = "force", short = 'f')]
205    pub force: bool,
206}
207
208#[derive(Args, Debug, Clone)]
209pub struct BundleBuildArgs {
210    /// Bundle directory (default: current directory)
211    #[arg(long = "bundle", short = 'b')]
212    pub bundle: Option<PathBuf>,
213    /// Output directory for portable bundle
214    #[arg(long = "out", short = 'o')]
215    pub out: PathBuf,
216    /// Tenant identifier
217    #[arg(long = "tenant", short = 't')]
218    pub tenant: Option<String>,
219    /// Team identifier
220    #[arg(long = "team")]
221    pub team: Option<String>,
222    /// Only include used providers
223    #[arg(long = "only-used-providers")]
224    pub only_used_providers: bool,
225    /// Run doctor validation after build
226    #[arg(long = "doctor")]
227    pub doctor: bool,
228    /// Skip doctor validation
229    #[arg(long = "skip-doctor")]
230    pub skip_doctor: bool,
231}
232
233#[derive(Args, Debug, Clone)]
234pub struct BundleListArgs {
235    /// Bundle directory (default: current directory)
236    #[arg(long = "bundle", short = 'b')]
237    pub bundle: Option<PathBuf>,
238    /// Filter by domain (messaging/events/secrets/oauth)
239    #[arg(long = "domain", short = 'd', default_value = "messaging")]
240    pub domain: String,
241    /// Show flows for a specific pack
242    #[arg(long = "pack", short = 'p')]
243    pub pack: Option<String>,
244    /// Output format (text/json)
245    #[arg(long = "format", default_value = "text")]
246    pub format: String,
247}
248
249#[derive(Args, Debug, Clone)]
250pub struct BundleStatusArgs {
251    /// Bundle directory (default: current directory)
252    #[arg(long = "bundle", short = 'b')]
253    pub bundle: Option<PathBuf>,
254    /// Output format (text/json)
255    #[arg(long = "format", default_value = "text")]
256    pub format: String,
257}