forjar 1.4.2

Rust-native Infrastructure as Code — bare-metal first, BLAKE3 state, provenance tracing
Documentation
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
//! Subcommand enums extracted from commands/mod.rs to keep it under 500 lines.

use clap::Subcommand;
use std::path::PathBuf;

/// FJ-260: Snapshot subcommands — named state checkpoints.
#[derive(Subcommand, Debug)]
pub enum SnapshotCmd {
    /// Save current state as a named snapshot
    Save {
        /// Snapshot name
        name: String,
        /// State directory
        #[arg(long, default_value = "state")]
        state_dir: PathBuf,
    },
    /// List available snapshots
    List {
        /// State directory
        #[arg(long, default_value = "state")]
        state_dir: PathBuf,
        /// Output as JSON
        #[arg(long)]
        json: bool,
    },
    /// Restore state from a named snapshot
    Restore {
        /// Snapshot name to restore
        name: String,
        /// State directory
        #[arg(long, default_value = "state")]
        state_dir: PathBuf,
        /// Skip confirmation
        #[arg(long)]
        yes: bool,
    },
    /// Delete a named snapshot
    Delete {
        /// Snapshot name to delete
        name: String,
        /// State directory
        #[arg(long, default_value = "state")]
        state_dir: PathBuf,
    },
}

/// FJ-1386: Generation subcommands — Nix-style generational state snapshots.
#[derive(Subcommand, Debug)]
pub enum GenerationCmd {
    /// List all state generations
    List {
        /// State directory
        #[arg(long, default_value = "state")]
        state_dir: PathBuf,
        /// Output as JSON
        #[arg(long)]
        json: bool,
    },
    /// Garbage-collect old generations
    Gc {
        /// Number of generations to keep
        #[arg(long, default_value = "5")]
        keep: u32,
        /// State directory
        #[arg(long, default_value = "state")]
        state_dir: PathBuf,
    },
    /// FJ-2003: Diff two generations
    Diff {
        /// Source generation number
        from: u32,
        /// Target generation number
        to: u32,
        /// State directory
        #[arg(long, default_value = "state")]
        state_dir: PathBuf,
        /// Output as JSON
        #[arg(long)]
        json: bool,
    },
}

/// Shell types for completion generation.
#[derive(Debug, Clone, clap::ValueEnum)]
pub enum CompletionShell {
    /// Generate bash completions.
    Bash,
    /// Generate zsh completions.
    Zsh,
    /// Generate fish completions.
    Fish,
}

/// FJ-210: Workspace subcommands.
#[derive(Subcommand, Debug)]
pub enum WorkspaceCmd {
    /// Create a new workspace
    New {
        /// Workspace name
        name: String,
    },
    /// List all workspaces
    List,
    /// Select (activate) a workspace
    Select {
        /// Workspace name
        name: String,
    },
    /// Delete a workspace and its state
    Delete {
        /// Workspace name
        name: String,
        /// Skip confirmation
        #[arg(long)]
        yes: bool,
    },
    /// Show current active workspace
    Current,
}

/// FJ-3500: Environment management subcommands.
#[derive(Subcommand, Debug)]
pub enum EnvironmentsCmd {
    /// List all defined environments
    List {
        /// Path to forjar.yaml
        #[arg(short, long, default_value = "forjar.yaml")]
        file: PathBuf,
        /// Output as JSON
        #[arg(long)]
        json: bool,
    },
    /// Diff two environments
    Diff {
        /// Source environment name
        source: String,
        /// Target environment name
        target: String,
        /// Path to forjar.yaml
        #[arg(short, long, default_value = "forjar.yaml")]
        file: PathBuf,
        /// Output as JSON
        #[arg(long)]
        json: bool,
    },
    /// Rollback an environment to a previous generation
    Rollback {
        /// Environment name to rollback
        env: String,
        /// State directory
        #[arg(long, default_value = "state")]
        state_dir: PathBuf,
        /// Number of generations to rollback
        #[arg(long, default_value = "1")]
        generations: u32,
        /// Skip confirmation
        #[arg(long)]
        yes: bool,
        /// JSON output
        #[arg(long)]
        json: bool,
    },
    /// Show promotion/rollback history for an environment
    History {
        /// Environment name
        env: String,
        /// State directory
        #[arg(long, default_value = "state")]
        state_dir: PathBuf,
        /// Maximum events to show
        #[arg(long, default_value = "20")]
        limit: usize,
        /// JSON output
        #[arg(long)]
        json: bool,
    },
}

/// FJ-3506: Promote between environments.
#[derive(clap::Args, Debug)]
pub struct PromoteArgs {
    /// Path to forjar.yaml
    #[arg(short, long, default_value = "forjar.yaml")]
    pub file: PathBuf,
    /// Target environment to promote to
    #[arg(short, long)]
    pub target: String,
    /// Skip approval prompt (use auto_approve from config)
    #[arg(long)]
    pub yes: bool,
    /// Dry-run: evaluate gates without applying
    #[arg(long)]
    pub dry_run: bool,
    /// JSON output
    #[arg(long)]
    pub json: bool,
}

/// FJ-3108: Rulebook management subcommands.
#[derive(Subcommand, Debug)]
pub enum RulesCmd {
    /// Validate rulebook YAML syntax and semantics
    Validate {
        /// Path to rulebook YAML file
        #[arg(short, long, default_value = "forjar.yaml")]
        file: PathBuf,
        /// JSON output
        #[arg(long)]
        json: bool,
    },
    /// Show event type coverage across rulebooks
    Coverage {
        /// Path to rulebook YAML file
        #[arg(short, long, default_value = "forjar.yaml")]
        file: PathBuf,
        /// JSON output
        #[arg(long)]
        json: bool,
    },
}

/// FJ-3403: Plugin management subcommands.
#[derive(Subcommand, Debug)]
pub enum PluginCmd {
    /// List installed plugins
    List {
        /// Plugin directory
        #[arg(long, default_value = "plugins")]
        plugin_dir: PathBuf,
        /// JSON output
        #[arg(long)]
        json: bool,
    },
    /// Verify a plugin manifest and WASM binary
    Verify {
        /// Path to plugin manifest YAML
        manifest: PathBuf,
        /// JSON output
        #[arg(long)]
        json: bool,
    },
    /// FJ-3407: Scaffold a new plugin project
    Init {
        /// Plugin name
        name: String,
        /// Output directory (default: plugins/<name>)
        #[arg(long)]
        output: Option<PathBuf>,
        /// JSON output
        #[arg(long)]
        json: bool,
    },
    /// Install a plugin from a local path or registry
    Install {
        /// Plugin source (directory path or name)
        source: String,
        /// Plugin directory to install into
        #[arg(long, default_value = "plugins")]
        plugin_dir: PathBuf,
        /// JSON output
        #[arg(long)]
        json: bool,
    },
    /// Build a WASM plugin from a Rust source directory
    Build {
        /// Path to plugin source directory (must contain Cargo.toml)
        #[arg(long)]
        path: PathBuf,
        /// Output directory for built plugin
        #[arg(long, default_value = "plugins")]
        output: Option<PathBuf>,
        /// JSON output
        #[arg(long)]
        json: bool,
    },
    /// Execute a plugin's check/apply/destroy via WASM runtime
    Run {
        /// Plugin name
        name: String,
        /// Operation to run: check, apply, or destroy
        #[arg(long, default_value = "check")]
        operation: String,
        /// Plugin directory
        #[arg(long, default_value = "plugins")]
        plugin_dir: PathBuf,
        /// JSON input config (inline or @file)
        #[arg(long, default_value = "{}")]
        config: String,
        /// JSON output
        #[arg(long)]
        json: bool,
    },
    /// Remove an installed plugin
    Remove {
        /// Plugin name to remove
        name: String,
        /// Plugin directory
        #[arg(long, default_value = "plugins")]
        plugin_dir: PathBuf,
        /// Skip confirmation
        #[arg(long)]
        yes: bool,
        /// JSON output
        #[arg(long)]
        json: bool,
    },
}

/// FJ-3304: State encryption arguments.
#[derive(clap::Args, Debug)]
pub struct StateEncryptArgs {
    /// State directory
    #[arg(long, default_value = "state")]
    pub state_dir: PathBuf,
    /// Passphrase for encryption (reads from stdin if not provided)
    #[arg(long)]
    pub passphrase: Option<String>,
    /// JSON output
    #[arg(long)]
    pub json: bool,
}

/// FJ-3304: State decryption arguments.
#[derive(clap::Args, Debug)]
pub struct StateDecryptArgs {
    /// State directory
    #[arg(long, default_value = "state")]
    pub state_dir: PathBuf,
    /// Passphrase for decryption
    #[arg(long)]
    pub passphrase: Option<String>,
    /// JSON output
    #[arg(long)]
    pub json: bool,
}

/// FJ-3309: State rekey arguments — re-encrypt with new passphrase.
#[derive(clap::Args, Debug)]
pub struct StateRekeyArgs {
    /// State directory
    #[arg(long, default_value = "state")]
    pub state_dir: PathBuf,
    /// Current passphrase
    #[arg(long)]
    pub old_passphrase: Option<String>,
    /// New passphrase
    #[arg(long)]
    pub new_passphrase: Option<String>,
    /// JSON output
    #[arg(long)]
    pub json: bool,
}

/// FJ-200: Secrets subcommands — age-encrypted secret management.
#[derive(Subcommand, Debug)]
pub enum SecretsCmd {
    /// Encrypt a value with age recipients
    Encrypt {
        /// Plaintext value to encrypt
        value: String,
        /// Age recipient public key(s)
        #[arg(short, long, required = true)]
        recipient: Vec<String>,
    },
    /// Decrypt an ENC[age,...] marker
    Decrypt {
        /// Encrypted marker to decrypt
        value: String,
        /// Path to age identity file
        #[arg(short, long)]
        identity: Option<PathBuf>,
    },
    /// Generate a new age identity (keypair)
    Keygen,
    /// Decrypt and display all secrets in a forjar.yaml
    View {
        /// Path to forjar.yaml
        #[arg(short, long, default_value = "forjar.yaml")]
        file: PathBuf,
        /// Path to age identity file
        #[arg(short, long)]
        identity: Option<PathBuf>,
    },
    /// Re-encrypt all ENC[age,...] markers with new recipients
    Rekey {
        /// Path to forjar.yaml
        #[arg(short, long, default_value = "forjar.yaml")]
        file: PathBuf,
        /// Path to age identity file
        #[arg(short, long)]
        identity: Option<PathBuf>,
        /// Age recipient public key(s)
        #[arg(short, long, required = true)]
        recipient: Vec<String>,
    },
    /// FJ-201: Rotate all secrets — decrypt and re-encrypt with new keys
    Rotate {
        /// Path to forjar.yaml
        #[arg(short, long, default_value = "forjar.yaml")]
        file: PathBuf,
        /// Path to age identity file
        #[arg(short, long)]
        identity: Option<PathBuf>,
        /// Age recipient public key(s)
        #[arg(short, long, required = true)]
        recipient: Vec<String>,
        /// Re-encrypt after rotation
        #[arg(long)]
        re_encrypt: bool,
        /// State directory
        #[arg(long, default_value = "state")]
        state_dir: PathBuf,
    },
}