1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
//! CLI definition for rigg — project-scoped command surface (0.18+).
use clap::{Args, Parser, Subcommand, ValueEnum};
use crate::commands;
use crate::commands::ExitCode;
#[derive(Parser)]
#[command(
name = "rigg",
about = "Configuration-as-code for Azure AI Search and Microsoft Foundry",
long_about = "Configuration-as-code for Azure AI Search and Microsoft Foundry.\n\n\
A rigg workspace holds one or more projects; each project owns its resource\n\
definitions (indexes, indexers, skillsets, knowledge bases, Foundry agents,\n\
deployments, ...) as JSON files. Pull, push, and diff operate on projects.\n\n\
New here? Run `rigg concepts` for the workspace/project model.",
version,
propagate_version = true
)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
/// Environment to target (default: the environment marked `default: true`)
#[arg(long, short = 'e', global = true, env = "RIGG_ENV")]
pub env: Option<String>,
/// Output format for machine consumption
#[arg(long, global = true, value_enum, default_value_t = OutputFormat::Text)]
pub output: OutputFormat,
/// Assume yes on all confirmation prompts
#[arg(long, short = 'y', global = true)]
pub yes: bool,
/// Never prompt; fail instead (implied when stdout is not a terminal)
#[arg(long, global = true)]
pub non_interactive: bool,
/// Increase logging verbosity (-v, -vv)
#[arg(short, long, global = true, action = clap::ArgAction::Count)]
pub verbose: u8,
/// Suppress non-error output
#[arg(short, long, global = true)]
pub quiet: bool,
/// Disable colored output
#[arg(long, global = true)]
pub no_color: bool,
/// Disable AI assistance for this invocation (even when `rigg ai` is enabled)
#[arg(long, global = true)]
pub no_ai: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum OutputFormat {
Text,
Json,
}
#[derive(Subcommand)]
pub enum Commands {
/// Initialize a new rigg workspace (discovers services via Azure CLI)
Init(InitArgs),
/// Scaffold a new project, resource, pipeline, or API spec
///
/// See `rigg concepts` for what a project is and when to use several.
New(NewArgs),
/// Copy a resource file locally under a new name
Copy(CopyArgs),
/// Download resource definitions from Azure into project files
///
/// Use `rigg adopt` to claim unmanaged remote resources into a project.
/// See `rigg concepts` for the project model.
Pull(PullArgs),
/// Adopt selected unmanaged Azure resources into a project
///
/// Selectors: `all`, a kind (e.g. `indexes`), or `<kind>/<name>`
/// (e.g. `agents/regulus`). Naming a resource the project already manages
/// together with --with-deps adopts its missing dependencies — useful
/// after new references appear (e.g. added via the portal).
/// See `rigg concepts` for the project model.
Adopt(AdoptArgs),
/// Upload local project files to Azure (create/update, in dependency order)
Push(PushArgs),
/// Compare local project files against live Azure services
Diff(DiffArgs),
/// Delete a project's resources from Azure
Delete(DeleteArgs),
/// Copy one environment's project tree into another, locally
///
/// A→B and B→A are the same operation — the A/B sync + hot-swap
/// workflow. Correlates resources by their file stem (logical id), not
/// their physical (Azure) name. Pinned fields keep the target env's
/// existing values instead of being overwritten: the resource's `name`
/// (always), the kind's registry-default env-pinned fields (secrets,
/// write-only fields, and a few genuinely per-environment fields like an
/// Agent's `tools[].server_url`), and any extra paths named in the
/// target file's own `x-rigg-pin` annotation. New-in-target resources
/// are created verbatim from the source (stem preserved); resources that
/// only exist in the target are left untouched. Always previews before
/// writing; `--dry-run` stops there. Local only — never touches Azure;
/// run `rigg diff`/`rigg push` against the target env afterward to sync
/// it.
Promote(PromoteArgs),
/// Show sync status per project (incl. unmanaged remote resources)
Status(StatusArgs),
/// Describe the workspace: projects, resources, dependency graph
Describe(DescribeArgs),
/// Explain rigg's core model: workspace, projects, and how to choose boundaries
Concepts,
/// Validate local files: structure, references, ownership, secrets
Validate(ValidateArgs),
/// Manage deployment environments
Env {
#[command(subcommand)]
command: EnvCommands,
},
/// Manage Azure authentication
Auth {
#[command(subcommand)]
command: AuthCommands,
},
/// Manage AI features (powered by ailloy)
Ai {
#[command(subcommand)]
command: Option<AiCommands>,
},
/// MCP server for AI agents
Mcp(McpArgs),
/// CI/CD helpers
Ci {
#[command(subcommand)]
command: CiCommands,
},
/// Developer utilities
#[command(hide = true)]
Dev {
#[command(subcommand)]
command: DevCommands,
},
/// Generate shell completions
Completion {
/// Shell to generate completions for
#[arg(value_enum)]
shell: Shell,
},
/// Show version information
Version,
/// Print the rigg banner
#[command(hide = true)]
Logo,
}
#[derive(Args)]
pub struct InitArgs {
/// Folder to store rigg's files in (projects/, apis/, .rigg/), recorded
/// as `root:` in rigg.yaml. The workspace itself is always initialized
/// in the current directory (default: files alongside rigg.yaml)
#[arg(default_value = ".")]
pub path: String,
/// Azure AI Search service name (skips discovery)
#[arg(long)]
pub search_service: Option<String>,
/// Microsoft Foundry account name (skips discovery)
#[arg(long)]
pub foundry_account: Option<String>,
/// Microsoft Foundry project name (with --foundry-account)
#[arg(long)]
pub foundry_project: Option<String>,
/// Name for the initial environment
#[arg(long, default_value = "dev")]
pub env_name: String,
/// Skip ARM discovery even when logged in
#[arg(long)]
pub no_discovery: bool,
}
#[derive(Args)]
pub struct NewArgs {
/// What to scaffold: project | pipeline | api | a resource kind
/// (data-source, index, skillset, indexer, synonym-map, alias,
/// knowledge-source, knowledge-base, agent, deployment, connection, guardrail)
pub kind: String,
/// Name of the new project/resource/spec. Tip: name a project after the
/// thing it owns (e.g. the agent's name). No `/` or `\`, max 260 chars.
pub name: String,
/// Project to place the resource in (required for resources and pipelines
/// unless the workspace has exactly one project)
#[arg(long, short = 'p')]
pub project: Option<String>,
/// Data source type for data-source/pipeline scaffolds
#[arg(long = "type", value_name = "TYPE")]
pub ds_type: Option<String>,
/// Describe what you want in natural language; AI drafts the definition (requires ailloy)
#[arg(long)]
pub describe: Option<String>,
}
#[derive(Args)]
pub struct CopyArgs {
/// Source: [project:]<kind-dir>/<name> (e.g. indexes/my-index)
pub source: String,
/// Target: [project:]<name>
pub target: String,
}
#[derive(Args)]
pub struct PullArgs {
/// Project to pull (omit with --all)
pub project: Option<String>,
/// Pull all projects
#[arg(long)]
pub all: bool,
/// Poll for remote changes and keep pulling
#[arg(long)]
pub watch: bool,
/// Poll interval in seconds for --watch
#[arg(long, default_value_t = 20)]
pub interval: u64,
}
#[derive(Args)]
pub struct AdoptArgs {
/// Project to adopt the resources into (omit on a TTY for an interactive wizard)
pub project: Option<String>,
/// What to adopt: `all`, a kind (`indexes`), or `<kind>/<name>` (`agents/regulus`). Repeatable.
#[arg(value_name = "SELECTOR")]
pub selectors: Vec<String>,
/// Preview what would be adopted; write nothing
#[arg(long)]
pub dry_run: bool,
/// Also adopt each selected resource's upstream dependencies
#[arg(long)]
pub with_deps: bool,
}
#[derive(Args)]
pub struct PushArgs {
/// Project to push (omit with --all)
pub project: Option<String>,
/// Push all projects
#[arg(long)]
pub all: bool,
/// Show what would change without pushing
#[arg(long)]
pub dry_run: bool,
/// Delete remote resources whose local files were removed
#[arg(long)]
pub prune: bool,
/// Typed confirmation for protected environments (must equal the env name)
#[arg(long, value_name = "ENV")]
pub confirm_env: Option<String>,
}
#[derive(Args)]
pub struct DiffArgs {
/// Project to diff (omit with --all)
pub project: Option<String>,
/// Diff all projects
#[arg(long)]
pub all: bool,
/// Exit with code 5 when differences are found (for CI)
#[arg(long)]
pub exit_code: bool,
/// Output format
#[arg(long, value_enum, default_value_t = DiffFormat::Text)]
pub format: DiffFormat,
/// Compare against another environment instead of local files
#[arg(long, value_name = "ENV")]
pub compare_env: Option<String>,
/// Restrict to one resource: <kind-dir>/<name> (e.g. indexes/my-index)
#[arg(long, value_name = "KIND/NAME")]
pub only: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum DiffFormat {
Text,
Json,
Markdown,
}
#[derive(Args)]
pub struct DeleteArgs {
/// Project whose resources should be deleted
pub project: String,
/// Delete the project's resources from Azure (required)
#[arg(long)]
pub remote: bool,
/// Typed confirmation for protected environments (must equal the env name)
#[arg(long, value_name = "ENV")]
pub confirm_env: Option<String>,
}
#[derive(Args)]
pub struct PromoteArgs {
/// Project to promote
pub project: String,
/// Source environment
#[arg(long)]
pub from: String,
/// Target environment
#[arg(long)]
pub to: String,
/// Preview only; write nothing
#[arg(long)]
pub dry_run: bool,
}
#[derive(Args)]
pub struct StatusArgs {
/// Project to check (default: all)
pub project: Option<String>,
}
#[derive(Args)]
pub struct DescribeArgs {
/// Project to describe (default: all)
pub project: Option<String>,
}
#[derive(Args)]
pub struct ValidateArgs {
/// Project to validate (default: all)
pub project: Option<String>,
/// Enable stricter checks (cross-service reference resolution)
#[arg(long)]
pub strict: bool,
}
#[derive(Subcommand)]
pub enum EnvCommands {
/// List configured environments
List,
/// Show environment details
Show { name: Option<String> },
/// Set the default environment
SetDefault { name: String },
/// Add a new environment
Add {
name: String,
/// Azure AI Search service name
#[arg(long)]
search_service: Option<String>,
/// Foundry account name
#[arg(long)]
foundry_account: Option<String>,
/// Foundry project name
#[arg(long)]
foundry_project: Option<String>,
},
/// Remove an environment
Remove { name: String },
}
#[derive(Subcommand)]
pub enum AuthCommands {
/// Log in to Azure (delegates to Azure CLI)
Login {
/// Use service principal from environment variables
#[arg(long)]
service_principal: bool,
/// Use managed identity
#[arg(long)]
identity: bool,
},
/// Show authentication status
Status,
/// Log out
Logout,
/// Verify service-to-service identities and RBAC for the workspace
Doctor {
/// Attempt to fix missing role assignments / identities
#[arg(long)]
fix: bool,
},
}
#[derive(Subcommand)]
pub enum AiCommands {
/// Test AI connectivity with a message
Test { message: Option<String> },
/// Enable AI features for rigg
Enable,
/// Disable AI features for rigg
Disable,
/// Configure the AI provider (interactive)
Config,
/// Show AI status
Status,
/// Emit the rigg agent skill
Skill {
/// Write skill markdown to stdout
#[arg(long)]
emit: bool,
/// Print the AI reference document
#[arg(long)]
reference: bool,
},
}
#[derive(Args)]
pub struct McpArgs {
#[command(subcommand)]
pub command: McpCommands,
}
#[derive(Subcommand)]
pub enum McpCommands {
/// Run the MCP server on stdio
Serve,
/// Register rigg's MCP server with an AI tool
Install {
/// Tool to install for
#[arg(value_enum, default_value_t = McpTarget::ClaudeCode)]
target: McpTarget,
/// Installation scope
#[arg(long, value_enum, default_value_t = McpScope::Workspace)]
scope: McpScope,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum McpTarget {
ClaudeCode,
VsCode,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum McpScope {
Workspace,
Global,
}
#[derive(Subcommand)]
pub enum CiCommands {
/// Scaffold CI workflows (validate on PR, deploy on merge, nightly drift)
Init {
/// CI provider
#[arg(default_value = "github")]
provider: String,
/// Overwrite existing workflow files
#[arg(long)]
force: bool,
},
}
#[derive(Subcommand)]
pub enum DevCommands {
/// Check whether newer Azure API versions are available
ApiCheck,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum Shell {
Bash,
Zsh,
Fish,
Powershell,
}
impl Cli {
/// Execute the parsed command. Returns the process exit code.
pub async fn run(self) -> ExitCode {
let ctx = commands::GlobalContext::from_cli(&self);
let result = match self.command {
Commands::Init(args) => commands::init::run(&ctx, args).await,
Commands::New(args) => commands::new::run(&ctx, args).await,
Commands::Copy(args) => commands::copy::run(&ctx, args),
Commands::Pull(args) => commands::pull::run(&ctx, args).await,
Commands::Adopt(args) => commands::adopt::run(&ctx, args).await,
Commands::Push(args) => commands::push::run(&ctx, args).await,
Commands::Diff(args) => commands::diff::run(&ctx, args).await,
Commands::Delete(args) => commands::delete::run(&ctx, args).await,
Commands::Promote(args) => commands::promote::run(&ctx, args),
Commands::Status(args) => commands::status::run(&ctx, args).await,
Commands::Describe(args) => commands::describe::run(&ctx, args),
Commands::Concepts => commands::concepts::run(&ctx),
Commands::Validate(args) => commands::validate::run(&ctx, args),
Commands::Env { command } => commands::env::run(&ctx, command).await,
Commands::Auth { command } => commands::auth::run(&ctx, command).await,
Commands::Ai { command } => commands::ai::run(command).await,
Commands::Mcp(args) => commands::mcp_cmd::run(&ctx, args).await,
Commands::Ci { command } => commands::ci::run(&ctx, command),
Commands::Dev { command } => commands::dev::run(&ctx, command).await,
Commands::Completion { shell } => commands::completion::run(shell),
Commands::Version => {
crate::banner::print_banner_with_version();
Ok(())
}
Commands::Logo => {
crate::banner::print_banner_with_version();
Ok(())
}
};
commands::exit_code_for(result)
}
}