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