1use std::path::PathBuf;
2
3use crate::secrets_cli::SecretsCommand;
4use clap::{Args, Parser, Subcommand, ValueEnum};
5use greentic_component::cmd::{
6 build::BuildArgs as ComponentBuildArgs, doctor::DoctorArgs as ComponentDoctorArgs,
7 flow::FlowCommand as ComponentFlowCommand, hash::HashArgs as ComponentHashArgs,
8 inspect::InspectArgs as ComponentInspectArgs, new::NewArgs as ComponentNewArgs,
9 store::StoreCommand as ComponentStoreCommand,
10 templates::TemplatesArgs as ComponentTemplatesArgs,
11};
12
13#[derive(Parser, Debug)]
14#[command(name = "greentic-dev")]
15#[command(version)]
16#[command(about = "Greentic developer tooling CLI")]
17pub struct Cli {
18 #[command(subcommand)]
19 pub command: Command,
20}
21
22#[derive(Subcommand, Debug)]
23pub enum Command {
24 #[command(subcommand)]
26 Flow(FlowCommand),
27 #[command(subcommand)]
29 Pack(PackCommand),
30 #[command(subcommand)]
32 Component(ComponentCommand),
33 #[command(subcommand)]
35 Config(ConfigCommand),
36 #[command(subcommand)]
38 Mcp(McpCommand),
39 #[command(subcommand)]
41 Gui(GuiCommand),
42 #[command(subcommand)]
44 Secrets(SecretsCommand),
45}
46
47#[derive(Subcommand, Debug)]
48pub enum FlowCommand {
49 Validate(FlowDoctorArgs),
51 Doctor(FlowDoctorArgs),
53 AddStep(Box<FlowAddStepArgs>),
55}
56
57#[derive(Args, Debug)]
58pub struct FlowDoctorArgs {
59 #[arg(
61 value_name = "ARGS",
62 trailing_var_arg = true,
63 allow_hyphen_values = true
64 )]
65 pub passthrough: Vec<String>,
66}
67
68#[derive(Args, Debug)]
69pub struct FlowAddStepArgs {
70 #[arg(long = "flow")]
72 pub flow_path: PathBuf,
73 #[arg(long = "after")]
75 pub after: Option<String>,
76 #[arg(long = "mode", value_enum, default_value = "default")]
78 pub mode: FlowAddStepMode,
79 #[arg(long = "component")]
81 pub component_id: Option<String>,
82 #[arg(long = "component-ref")]
84 pub component_ref: Option<String>,
85 #[arg(long = "local-wasm")]
87 pub local_wasm: Option<PathBuf>,
88 #[arg(long = "pin")]
90 pub pin: bool,
91 #[arg(long = "pack-alias")]
93 pub pack_alias: Option<String>,
94 #[arg(long = "operation")]
96 pub operation: Option<String>,
97 #[arg(long = "payload", default_value = "{}")]
99 pub payload: String,
100 #[arg(long = "routing-out")]
102 pub routing_out: bool,
103 #[arg(long = "routing-reply")]
105 pub routing_reply: bool,
106 #[arg(long = "routing-next")]
108 pub routing_next: Option<String>,
109 #[arg(long = "routing-multi-to")]
111 pub routing_multi_to: Option<String>,
112 #[arg(long = "routing-json")]
114 pub routing_json: Option<PathBuf>,
115 #[arg(long = "routing-to-anchor")]
117 pub routing_to_anchor: bool,
118 #[arg(long = "config-flow")]
120 pub config_flow: Option<PathBuf>,
121 #[arg(long = "answers")]
123 pub answers: Option<String>,
124 #[arg(long = "answers-file")]
126 pub answers_file: Option<PathBuf>,
127 #[arg(long = "allow-cycles")]
129 pub allow_cycles: bool,
130 #[arg(long = "write")]
132 pub write: bool,
133 #[arg(long = "validate-only")]
135 pub validate_only: bool,
136 #[arg(long = "manifest")]
138 pub manifests: Vec<PathBuf>,
139 #[arg(long = "node-id")]
141 pub node_id: Option<String>,
142 #[arg(long = "verbose")]
144 pub verbose: bool,
145}
146
147#[derive(Copy, Clone, Debug, Eq, PartialEq, ValueEnum)]
148pub enum FlowAddStepMode {
149 Default,
150 Config,
151}
152
153#[derive(Subcommand, Debug)]
154pub enum GuiCommand {
155 Serve(GuiServeArgs),
157 PackDev(GuiPackDevArgs),
159}
160
161#[derive(Args, Debug)]
162pub struct GuiServeArgs {
163 #[arg(long = "config")]
165 pub config: Option<PathBuf>,
166 #[arg(long = "bind")]
168 pub bind: Option<String>,
169 #[arg(long = "domain")]
171 pub domain: Option<String>,
172 #[arg(long = "gui-bin")]
174 pub gui_bin: Option<PathBuf>,
175 #[arg(long = "no-cargo-fallback")]
177 pub no_cargo_fallback: bool,
178 #[arg(long = "open-browser")]
180 pub open_browser: bool,
181}
182
183#[derive(Args, Debug, Clone)]
184pub struct GuiPackDevArgs {
185 #[arg(long = "dir")]
187 pub dir: PathBuf,
188 #[arg(long = "output")]
190 pub output: PathBuf,
191 #[arg(long = "kind", value_enum, default_value = "layout")]
193 pub kind: GuiPackKind,
194 #[arg(long = "entrypoint", default_value = "index.html")]
196 pub entrypoint: String,
197 #[arg(long = "manifest")]
199 pub manifest: Option<PathBuf>,
200 #[arg(long = "feature-route")]
202 pub feature_route: Option<String>,
203 #[arg(long = "feature-html", default_value = "index.html")]
205 pub feature_html: String,
206 #[arg(long = "feature-authenticated")]
208 pub feature_authenticated: bool,
209 #[arg(long = "build-cmd")]
211 pub build_cmd: Option<String>,
212 #[arg(long = "no-build")]
214 pub no_build: bool,
215}
216
217#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
218pub enum GuiPackKind {
219 Layout,
220 Feature,
221}
222
223#[derive(Subcommand, Debug)]
224pub enum PackCommand {
225 Build(PackcArgs),
227 Lint(PackcArgs),
229 Components(PackcArgs),
231 Update(PackcArgs),
233 New(PackcArgs),
235 Sign(PackcArgs),
237 Verify(PackcArgs),
239 Gui(PackcArgs),
241 Inspect(PackInspectArgs),
243 Doctor(PackInspectArgs),
245 Plan(PackPlanArgs),
247 #[command(subcommand)]
249 Events(PackEventsCommand),
250 Config(PackcArgs),
252 Run(PackRunArgs),
254 Init(PackInitArgs),
256 NewProvider(PackNewProviderArgs),
258}
259
260#[derive(Args, Debug)]
261pub struct PackRunArgs {
262 #[arg(short = 'p', long = "pack")]
264 pub pack: PathBuf,
265 #[arg(long = "entry")]
267 pub entry: Option<String>,
268 #[arg(long = "input")]
270 pub input: Option<String>,
271 #[arg(long = "json")]
273 pub json: bool,
274 #[arg(long = "offline")]
276 pub offline: bool,
277 #[arg(long = "mock-exec", hide = true)]
279 pub mock_exec: bool,
280 #[arg(long = "allow-external", hide = true)]
282 pub allow_external: bool,
283 #[arg(long = "mock-external", hide = true)]
285 pub mock_external: bool,
286 #[arg(long = "mock-external-payload", hide = true)]
288 pub mock_external_payload: Option<PathBuf>,
289 #[arg(long = "secrets-seed", hide = true)]
291 pub secrets_seed: Option<PathBuf>,
292 #[arg(long = "policy", default_value = "devok", value_enum)]
294 pub policy: RunPolicyArg,
295 #[arg(long = "otlp")]
297 pub otlp: Option<String>,
298 #[arg(long = "allow")]
300 pub allow: Option<String>,
301 #[arg(long = "mocks", default_value = "on", value_enum)]
303 pub mocks: MockSettingArg,
304 #[arg(long = "artifacts")]
306 pub artifacts: Option<PathBuf>,
307}
308
309#[derive(Args, Debug)]
310pub struct PackInitArgs {
311 pub from: String,
313 #[arg(long = "profile")]
315 pub profile: Option<String>,
316}
317
318#[derive(Args, Debug)]
319pub struct PackNewProviderArgs {
320 #[arg(long = "pack")]
322 pub pack: PathBuf,
323 #[arg(long = "id")]
325 pub id: String,
326 #[arg(long = "runtime")]
328 pub runtime: String,
329 #[arg(long = "kind")]
331 pub kind: Option<String>,
332 #[arg(long = "manifest")]
334 pub manifest: Option<PathBuf>,
335 #[arg(long = "dry-run")]
337 pub dry_run: bool,
338 #[arg(long = "force")]
340 pub force: bool,
341 #[arg(long = "json")]
343 pub json: bool,
344 #[arg(long = "scaffold-files")]
346 pub scaffold_files: bool,
347}
348
349#[derive(Args, Debug, Clone, Default)]
350#[command(disable_help_flag = true)]
351pub struct PackcArgs {
352 #[arg(
354 value_name = "ARGS",
355 trailing_var_arg = true,
356 allow_hyphen_values = true
357 )]
358 pub passthrough: Vec<String>,
359}
360
361#[derive(Args, Debug)]
362pub struct PackInspectArgs {
363 #[arg(value_name = "PATH")]
365 pub path: PathBuf,
366 #[arg(long, value_enum, default_value = "devok")]
368 pub policy: PackPolicyArg,
369 #[arg(long)]
371 pub json: bool,
372}
373
374#[derive(Subcommand, Debug)]
375pub enum PackEventsCommand {
376 List(PackEventsListArgs),
378}
379
380#[derive(Args, Debug)]
381pub struct PackEventsListArgs {
382 #[arg(value_name = "PATH")]
384 pub path: PathBuf,
385 #[arg(long, value_enum, default_value = "table")]
387 pub format: PackEventsFormatArg,
388 #[arg(long)]
390 pub verbose: bool,
391}
392
393#[derive(Args, Debug)]
394pub struct PackPlanArgs {
395 #[arg(value_name = "PATH")]
397 pub input: PathBuf,
398 #[arg(long, default_value = "tenant-local")]
400 pub tenant: String,
401 #[arg(long, default_value = "local")]
403 pub environment: String,
404 #[arg(long)]
406 pub json: bool,
407 #[arg(long)]
409 pub verbose: bool,
410}
411
412#[derive(Subcommand, Debug, Clone)]
413pub enum ComponentCommand {
414 Add(ComponentAddArgs),
416 New(ComponentNewArgs),
418 Templates(ComponentTemplatesArgs),
420 Doctor(ComponentDoctorArgs),
422 Inspect(ComponentInspectArgs),
424 Hash(ComponentHashArgs),
426 Build(ComponentBuildArgs),
428 #[command(subcommand)]
430 Flow(ComponentFlowCommand),
431 #[command(subcommand)]
433 Store(ComponentStoreCommand),
434}
435
436#[derive(Args, Debug, Clone)]
437pub struct ComponentAddArgs {
438 pub coordinate: String,
440 #[arg(long = "profile")]
442 pub profile: Option<String>,
443 #[arg(long = "intent", default_value = "dev", value_enum)]
445 pub intent: DevIntentArg,
446}
447
448#[derive(Subcommand, Debug)]
449pub enum McpCommand {
450 Doctor(McpDoctorArgs),
452}
453
454#[derive(Args, Debug)]
455pub struct McpDoctorArgs {
456 pub provider: String,
458 #[arg(long = "json")]
460 pub json: bool,
461}
462
463#[derive(Subcommand, Debug)]
464pub enum ConfigCommand {
465 Set(ConfigSetArgs),
467}
468
469#[derive(Args, Debug)]
470pub struct ConfigSetArgs {
471 pub key: String,
473 pub value: String,
475 #[arg(long = "file")]
477 pub file: Option<PathBuf>,
478}
479
480#[derive(Copy, Clone, Debug, ValueEnum)]
481pub enum PackSignArg {
482 Dev,
483 None,
484}
485
486#[derive(Copy, Clone, Debug, ValueEnum)]
487pub enum PackPolicyArg {
488 Devok,
489 Strict,
490}
491
492#[derive(Copy, Clone, Debug, ValueEnum)]
493pub enum RunPolicyArg {
494 Strict,
495 Devok,
496}
497
498#[derive(Copy, Clone, Debug, ValueEnum)]
499pub enum VerifyPolicyArg {
500 Strict,
501 Devok,
502}
503
504#[derive(Copy, Clone, Debug, ValueEnum)]
505pub enum MockSettingArg {
506 On,
507 Off,
508}
509
510#[derive(Copy, Clone, Debug, ValueEnum)]
511pub enum PackEventsFormatArg {
512 Table,
513 Json,
514 Yaml,
515}
516
517#[derive(Copy, Clone, Debug, ValueEnum)]
518pub enum ConfigFlowModeArg {
519 Default,
520 Custom,
521}
522#[derive(Copy, Clone, Debug, ValueEnum)]
523pub enum DevIntentArg {
524 Dev,
525 Runtime,
526}
527
528#[cfg(test)]
529mod tests {}