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
//! Command-line interface.
pub mod add;
pub mod admit;
pub mod banner;
pub mod completions;
pub mod dot;
pub mod init;
pub mod knock;
pub mod output;
pub mod pending;
pub mod resolve;
pub mod run;
pub mod secrets;
pub mod setup;
pub mod shell;
pub mod sync;
pub mod team;
pub mod whoami;
// Subcommand groups
pub mod check;
pub mod vault;
// Platform-specific commands
#[cfg(target_os = "macos")]
pub mod migrate_keychain;
#[cfg(target_os = "macos")]
pub mod reset_keychain;
use clap::builder::styling::{AnsiColor, Effects, Styles};
use clap::{Parser, Subcommand};
const STYLES: Styles = Styles::styled()
.header(AnsiColor::Green.on_default().effects(Effects::BOLD))
.usage(AnsiColor::Green.on_default().effects(Effects::BOLD))
.literal(AnsiColor::Cyan.on_default().effects(Effects::BOLD))
.placeholder(AnsiColor::Cyan.on_default())
.valid(AnsiColor::Green.on_default().effects(Effects::BOLD))
.invalid(AnsiColor::Red.on_default().effects(Effects::BOLD))
.error(AnsiColor::Red.on_default().effects(Effects::BOLD));
/// Dugout - Git-native secrets manager for development teams.
#[derive(Parser)]
#[command(
name = "dugout",
about = "Git-native secrets manager for development teams",
version,
styles = STYLES
)]
pub struct Cli {
/// Enable verbose logging output
#[arg(short = 'v', long, global = true)]
pub verbose: bool,
/// Select vault (e.g., "dev", "prod"). Uses .dugout.toml by default.
#[arg(long = "vault", global = true, env = "DUGOUT_VAULT")]
pub vault: Option<String>,
#[command(subcommand)]
pub command: Command,
}
/// Top-level commands.
#[derive(Subcommand)]
pub enum Command {
/// Generate global identity at ~/.dugout/identity
Setup {
/// Overwrite existing identity
#[arg(short, long)]
force: bool,
/// Identity name (non-interactive)
#[arg(short, long)]
name: Option<String>,
/// Write private key to path (use - for stdout)
#[arg(short, long, value_name = "PATH")]
output: Option<String>,
},
/// Print your public key
Whoami,
/// Initialize dugout in the current directory
Init {
/// Your name (used as recipient identifier)
#[arg(short, long)]
name: Option<String>,
/// Skip ASCII art banner
#[arg(long)]
no_banner: bool,
/// KMS key for hybrid encryption (auto-detects AWS/GCP from format)
#[arg(long, value_name = "KEY")]
kms: Option<String>,
},
/// Add a secret interactively with hidden input
Add {
/// Secret key (e.g., DATABASE_URL)
key: String,
},
/// Set a secret value
Set {
/// Secret key (e.g., DATABASE_URL)
key: String,
/// Secret value
value: String,
/// Overwrite if exists
#[arg(short, long)]
force: bool,
},
/// Get a secret value
Get {
/// Secret key
key: String,
},
/// Remove a secret
Rm {
/// Secret key
key: String,
},
/// List all secret keys
List {
/// Output as JSON
#[arg(long)]
json: bool,
},
/// Request access to a vault
Knock {
/// Your name (optional, will prompt if not provided)
name: Option<String>,
},
/// List pending access requests
Pending,
/// Approve an access request
Admit {
/// Name of the person to admit
name: String,
},
/// Re-encrypt secrets for the current recipient set
Sync {
/// Show what would change without doing it
#[arg(long)]
dry_run: bool,
/// Force re-encryption even if already in sync
#[arg(long)]
force: bool,
},
/// Auto-detect project and run with secrets
#[command(name = ".")]
Dot,
/// Run a command with secrets injected as env vars
Run {
/// Command and arguments to run
#[arg(trailing_var_arg = true)]
command: Vec<String>,
},
/// Spawn a shell with secrets loaded as environment variables
Env,
/// Manage team members
#[command(subcommand)]
Team(TeamAction),
/// Secret lifecycle operations (lock, unlock, import, export, diff, rotate)
#[command(subcommand)]
Secrets(SecretsCommand),
/// Run diagnostic checks (status, audit)
#[command(subcommand)]
Check(CheckCommand),
/// Vault management commands
#[command(subcommand)]
Vault(VaultCommand),
/// Generate shell completions
Completions {
/// Shell to generate completions for
#[arg(value_enum)]
shell: Shell,
},
/// Migrate file-based identities to macOS Keychain (macOS only)
#[cfg(target_os = "macos")]
MigrateKeychain {
/// Delete files after successful migration
#[arg(long)]
delete: bool,
/// Skip confirmation prompts
#[arg(short, long)]
force: bool,
},
/// Remove identities from macOS Keychain (macOS only)
#[cfg(target_os = "macos")]
ResetKeychain {
/// Account name to remove (e.g., "global", "project-id"), or omit to specify --all
account: Option<String>,
/// Remove all dugout identities from Keychain
#[arg(long)]
all: bool,
/// Skip confirmation prompt
#[arg(short, long)]
force: bool,
},
}
/// Supported shells for completions.
#[derive(clap::ValueEnum, Clone, Debug)]
pub enum Shell {
Bash,
Zsh,
Fish,
PowerShell,
}
/// Team subcommands.
#[derive(Subcommand)]
pub enum TeamAction {
/// Add a team member by their public key
Add {
/// Member name
name: String,
/// age public key
key: String,
},
/// List team members
List {
/// Output as JSON
#[arg(long)]
json: bool,
},
/// Remove a team member
Rm {
/// Member name
name: String,
},
}
/// Secrets lifecycle subcommands.
#[derive(Subcommand)]
pub enum SecretsCommand {
/// Encrypt all secrets (verify encryption status)
Lock,
/// Decrypt secrets to local .env file
Unlock,
/// Import secrets from a .env file
Import {
/// Path to .env file
path: String,
},
/// Export secrets as .env format
Export,
/// Show diff between .dugout.toml and .env
Diff,
/// Rotate the project keypair and re-encrypt all secrets
Rotate,
}
/// Check/diagnostic subcommands.
#[derive(Subcommand)]
pub enum CheckCommand {
/// Show quick status overview
Status,
/// Audit git history for leaked secrets
Audit,
}
/// Vault management subcommands.
#[derive(Subcommand)]
pub enum VaultCommand {
/// List all vaults in the repository
List {
/// Output as JSON
#[arg(long)]
json: bool,
},
}
/// Execute a command with vault context.
pub fn execute(command: Command, vault: Option<String>) -> crate::error::Result<()> {
use Command::*;
match command {
Setup {
force,
name,
output,
} => setup::execute(force, name, output),
Whoami => whoami::execute(),
Init {
name,
no_banner,
kms,
} => init::execute(name, no_banner, kms, vault),
Add { key } => add::execute(&key, vault),
Set { key, value, force } => secrets::set(&key, &value, force, vault),
Get { key } => secrets::get(&key, vault),
Rm { key } => secrets::rm(&key, vault),
List { json } => secrets::list(json, vault),
Knock { name } => knock::execute(name, vault),
Pending => pending::execute(vault),
Admit { name } => admit::execute(&name, vault),
Sync { dry_run, force } => sync::execute(dry_run, force, vault),
Dot => dot::execute(vault),
Run { command: cmd } => run::execute(&cmd, vault),
Env => shell::execute(vault),
Team(action) => match action {
TeamAction::Add { name, key } => team::add(&name, &key, vault),
TeamAction::List { json } => team::list(json, vault),
TeamAction::Rm { name } => team::rm(&name, vault),
},
Secrets(cmd) => match cmd {
SecretsCommand::Lock => secrets::lock(vault),
SecretsCommand::Unlock => secrets::unlock(vault),
SecretsCommand::Import { path } => secrets::import(&path, vault),
SecretsCommand::Export => secrets::export(vault),
SecretsCommand::Diff => secrets::diff(vault),
SecretsCommand::Rotate => secrets::rotate(vault),
},
Check(cmd) => match cmd {
CheckCommand::Status => check::status(vault),
CheckCommand::Audit => check::audit(),
},
Vault(cmd) => match cmd {
VaultCommand::List { json } => vault::list::execute(json),
},
Completions { shell } => completions::execute(shell),
#[cfg(target_os = "macos")]
MigrateKeychain { delete, force } => migrate_keychain::execute(delete, force),
#[cfg(target_os = "macos")]
ResetKeychain {
account,
all,
force,
} => reset_keychain::execute(account, all, force),
}
}