1use std::{ffi::OsString, 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 Flow(PassthroughArgs),
26 Pack(PassthroughArgs),
28 Component(PassthroughArgs),
30 #[command(subcommand)]
32 Config(ConfigCommand),
33 #[command(subcommand)]
35 Mcp(McpCommand),
36 Gui(PassthroughArgs),
38 #[command(subcommand)]
40 Secrets(SecretsCommand),
41 Cbor(CborArgs),
43}
44
45#[derive(Args, Debug, Clone)]
46#[command(disable_help_flag = true)]
47pub struct PassthroughArgs {
48 #[arg(
50 value_name = "ARGS",
51 trailing_var_arg = true,
52 allow_hyphen_values = true
53 )]
54 pub args: Vec<OsString>,
55}
56
57#[derive(Subcommand, Debug)]
58pub enum FlowCommand {
59 Doctor(FlowDoctorArgs),
61 New(FlowPassthroughArgs),
63 Update(FlowPassthroughArgs),
65 AddStep(Box<FlowAddStepArgs>),
67 UpdateStep(FlowPassthroughArgs),
69 DeleteStep(FlowPassthroughArgs),
71 BindComponent(FlowPassthroughArgs),
73}
74
75#[derive(Args, Debug)]
76pub struct FlowDoctorArgs {
77 #[arg(
79 value_name = "ARGS",
80 trailing_var_arg = true,
81 allow_hyphen_values = true
82 )]
83 pub passthrough: Vec<String>,
84}
85
86#[derive(Args, Debug)]
87pub struct FlowPassthroughArgs {
88 #[arg(
90 value_name = "ARGS",
91 trailing_var_arg = true,
92 allow_hyphen_values = true
93 )]
94 pub passthrough: Vec<String>,
95}
96
97#[derive(Args, Debug)]
98pub struct FlowAddStepArgs {
99 #[arg(long = "flow")]
101 pub flow_path: PathBuf,
102 #[arg(long = "after")]
104 pub after: Option<String>,
105 #[arg(long = "mode", value_enum, default_value = "default")]
107 pub mode: FlowAddStepMode,
108 #[arg(long = "component")]
110 pub component_id: Option<String>,
111 #[arg(long = "component-ref")]
113 pub component_ref: Option<String>,
114 #[arg(long = "local-wasm")]
116 pub local_wasm: Option<PathBuf>,
117 #[arg(long = "pin")]
119 pub pin: bool,
120 #[arg(long = "pack-alias")]
122 pub pack_alias: Option<String>,
123 #[arg(long = "operation")]
125 pub operation: Option<String>,
126 #[arg(long = "payload", default_value = "{}")]
128 pub payload: String,
129 #[arg(long = "routing-out")]
131 pub routing_out: bool,
132 #[arg(long = "routing-reply")]
134 pub routing_reply: bool,
135 #[arg(long = "routing-next")]
137 pub routing_next: Option<String>,
138 #[arg(long = "routing-multi-to")]
140 pub routing_multi_to: Option<String>,
141 #[arg(long = "routing-json")]
143 pub routing_json: Option<PathBuf>,
144 #[arg(long = "routing-to-anchor")]
146 pub routing_to_anchor: bool,
147 #[arg(long = "config-flow")]
149 pub config_flow: Option<PathBuf>,
150 #[arg(long = "answers")]
152 pub answers: Option<String>,
153 #[arg(long = "answers-file")]
155 pub answers_file: Option<PathBuf>,
156 #[arg(long = "allow-cycles")]
158 pub allow_cycles: bool,
159 #[arg(long = "write")]
161 pub write: bool,
162 #[arg(long = "validate-only")]
164 pub validate_only: bool,
165 #[arg(long = "manifest")]
167 pub manifests: Vec<PathBuf>,
168 #[arg(long = "node-id")]
170 pub node_id: Option<String>,
171 #[arg(long = "verbose")]
173 pub verbose: bool,
174}
175
176#[derive(Copy, Clone, Debug, Eq, PartialEq, ValueEnum)]
177pub enum FlowAddStepMode {
178 Default,
179 Config,
180}
181
182#[derive(Subcommand, Debug)]
183pub enum GuiCommand {
184 Serve(GuiServeArgs),
186 PackDev(GuiPackDevArgs),
188}
189
190#[derive(Args, Debug)]
191pub struct GuiServeArgs {
192 #[arg(long = "config")]
194 pub config: Option<PathBuf>,
195 #[arg(long = "bind")]
197 pub bind: Option<String>,
198 #[arg(long = "domain")]
200 pub domain: Option<String>,
201 #[arg(long = "gui-bin")]
203 pub gui_bin: Option<PathBuf>,
204 #[arg(long = "no-cargo-fallback")]
206 pub no_cargo_fallback: bool,
207 #[arg(long = "open-browser")]
209 pub open_browser: bool,
210}
211
212#[derive(Args, Debug, Clone)]
213pub struct GuiPackDevArgs {
214 #[arg(long = "dir")]
216 pub dir: PathBuf,
217 #[arg(long = "output")]
219 pub output: PathBuf,
220 #[arg(long = "kind", value_enum, default_value = "layout")]
222 pub kind: GuiPackKind,
223 #[arg(long = "entrypoint", default_value = "index.html")]
225 pub entrypoint: String,
226 #[arg(long = "manifest")]
228 pub manifest: Option<PathBuf>,
229 #[arg(long = "feature-route")]
231 pub feature_route: Option<String>,
232 #[arg(long = "feature-html", default_value = "index.html")]
234 pub feature_html: String,
235 #[arg(long = "feature-authenticated")]
237 pub feature_authenticated: bool,
238 #[arg(long = "build-cmd")]
240 pub build_cmd: Option<String>,
241 #[arg(long = "no-build")]
243 pub no_build: bool,
244}
245
246#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
247pub enum GuiPackKind {
248 Layout,
249 Feature,
250}
251
252#[derive(Subcommand, Debug)]
253pub enum PackCommand {
254 Build(PackcArgs),
256 Lint(PackcArgs),
258 Components(PackcArgs),
260 Update(PackcArgs),
262 New(PackcArgs),
264 Sign(PackcArgs),
266 Verify(PackcArgs),
268 Gui(PackcArgs),
270 Inspect(PackInspectArgs),
272 Doctor(PackInspectArgs),
274 Plan(PackPlanArgs),
276 #[command(subcommand)]
278 Events(PackEventsCommand),
279 Config(PackcArgs),
281 Run(PackRunArgs),
283 Init(PackInitArgs),
285 NewProvider(PackNewProviderArgs),
287}
288
289#[derive(Args, Debug)]
290pub struct PackRunArgs {
291 #[arg(short = 'p', long = "pack")]
293 pub pack: PathBuf,
294 #[arg(long = "entry")]
296 pub entry: Option<String>,
297 #[arg(long = "input")]
299 pub input: Option<String>,
300 #[arg(long = "json")]
302 pub json: bool,
303 #[arg(long = "offline")]
305 pub offline: bool,
306 #[arg(long = "mock-exec", hide = true)]
308 pub mock_exec: bool,
309 #[arg(long = "allow-external", hide = true)]
311 pub allow_external: bool,
312 #[arg(long = "mock-external", hide = true)]
314 pub mock_external: bool,
315 #[arg(long = "mock-external-payload", hide = true)]
317 pub mock_external_payload: Option<PathBuf>,
318 #[arg(long = "secrets-seed", hide = true)]
320 pub secrets_seed: Option<PathBuf>,
321 #[arg(long = "policy", default_value = "devok", value_enum)]
323 pub policy: RunPolicyArg,
324 #[arg(long = "otlp")]
326 pub otlp: Option<String>,
327 #[arg(long = "allow")]
329 pub allow: Option<String>,
330 #[arg(long = "mocks", default_value = "on", value_enum)]
332 pub mocks: MockSettingArg,
333 #[arg(long = "artifacts")]
335 pub artifacts: Option<PathBuf>,
336}
337
338#[derive(Args, Debug)]
339pub struct PackInitArgs {
340 pub from: String,
342 #[arg(long = "profile")]
344 pub profile: Option<String>,
345}
346
347#[derive(Args, Debug)]
348pub struct PackNewProviderArgs {
349 #[arg(long = "pack")]
351 pub pack: PathBuf,
352 #[arg(long = "id")]
354 pub id: String,
355 #[arg(long = "runtime")]
357 pub runtime: String,
358 #[arg(long = "kind")]
360 pub kind: Option<String>,
361 #[arg(long = "manifest")]
363 pub manifest: Option<PathBuf>,
364 #[arg(long = "dry-run")]
366 pub dry_run: bool,
367 #[arg(long = "force")]
369 pub force: bool,
370 #[arg(long = "json")]
372 pub json: bool,
373 #[arg(long = "scaffold-files")]
375 pub scaffold_files: bool,
376}
377
378#[derive(Args, Debug, Clone, Default)]
379#[command(disable_help_flag = true)]
380pub struct PackcArgs {
381 #[arg(
383 value_name = "ARGS",
384 trailing_var_arg = true,
385 allow_hyphen_values = true
386 )]
387 pub passthrough: Vec<String>,
388}
389
390#[derive(Args, Debug)]
391pub struct PackInspectArgs {
392 #[arg(value_name = "PATH")]
394 pub path: PathBuf,
395 #[arg(long, value_enum, default_value = "devok")]
397 pub policy: PackPolicyArg,
398 #[arg(long)]
400 pub json: bool,
401}
402
403#[derive(Subcommand, Debug)]
404pub enum PackEventsCommand {
405 List(PackEventsListArgs),
407}
408
409#[derive(Args, Debug)]
410pub struct PackEventsListArgs {
411 #[arg(value_name = "PATH")]
413 pub path: PathBuf,
414 #[arg(long, value_enum, default_value = "table")]
416 pub format: PackEventsFormatArg,
417 #[arg(long)]
419 pub verbose: bool,
420}
421
422#[derive(Args, Debug)]
423pub struct PackPlanArgs {
424 #[arg(value_name = "PATH")]
426 pub input: PathBuf,
427 #[arg(long, default_value = "tenant-local")]
429 pub tenant: String,
430 #[arg(long, default_value = "local")]
432 pub environment: String,
433 #[arg(long)]
435 pub json: bool,
436 #[arg(long)]
438 pub verbose: bool,
439}
440
441#[derive(Subcommand, Debug, Clone)]
442pub enum ComponentCommand {
443 Add(ComponentAddArgs),
445 New(ComponentNewArgs),
447 Templates(ComponentTemplatesArgs),
449 Doctor(ComponentDoctorArgs),
451 Inspect(ComponentInspectArgs),
453 Hash(ComponentHashArgs),
455 Build(ComponentBuildArgs),
457 #[command(subcommand)]
459 Flow(ComponentFlowCommand),
460 #[command(subcommand)]
462 Store(ComponentStoreCommand),
463}
464
465#[derive(Args, Debug, Clone)]
466pub struct ComponentAddArgs {
467 pub coordinate: String,
469 #[arg(long = "profile")]
471 pub profile: Option<String>,
472 #[arg(long = "intent", default_value = "dev", value_enum)]
474 pub intent: DevIntentArg,
475}
476
477#[derive(Subcommand, Debug)]
478pub enum McpCommand {
479 Doctor(McpDoctorArgs),
481}
482
483#[derive(Args, Debug)]
484pub struct McpDoctorArgs {
485 pub provider: String,
487 #[arg(long = "json")]
489 pub json: bool,
490}
491
492#[derive(Subcommand, Debug)]
493pub enum ConfigCommand {
494 Set(ConfigSetArgs),
496}
497
498#[derive(Args, Debug)]
499pub struct ConfigSetArgs {
500 pub key: String,
502 pub value: String,
504 #[arg(long = "file")]
506 pub file: Option<PathBuf>,
507}
508
509#[derive(Args, Debug)]
510pub struct CborArgs {
511 #[arg(value_name = "PATH")]
513 pub path: PathBuf,
514}
515
516#[derive(Copy, Clone, Debug, ValueEnum)]
517pub enum PackSignArg {
518 Dev,
519 None,
520}
521
522#[derive(Copy, Clone, Debug, ValueEnum)]
523pub enum PackPolicyArg {
524 Devok,
525 Strict,
526}
527
528#[derive(Copy, Clone, Debug, ValueEnum)]
529pub enum RunPolicyArg {
530 Strict,
531 Devok,
532}
533
534#[derive(Copy, Clone, Debug, ValueEnum)]
535pub enum VerifyPolicyArg {
536 Strict,
537 Devok,
538}
539
540#[derive(Copy, Clone, Debug, ValueEnum)]
541pub enum MockSettingArg {
542 On,
543 Off,
544}
545
546#[derive(Copy, Clone, Debug, ValueEnum)]
547pub enum PackEventsFormatArg {
548 Table,
549 Json,
550 Yaml,
551}
552
553#[derive(Copy, Clone, Debug, ValueEnum)]
554pub enum ConfigFlowModeArg {
555 Default,
556 Custom,
557}
558#[derive(Copy, Clone, Debug, ValueEnum)]
559pub enum DevIntentArg {
560 Dev,
561 Runtime,
562}
563
564#[cfg(test)]
565mod tests {}