use crate::targets::Target;
use crate::vault::SecretFormat;
use clap::{Args, Parser, Subcommand};
#[derive(Debug, Clone, Copy)]
pub struct CliFlags {
pub json: bool,
pub non_interactive: bool,
pub dry_run: bool,
pub yes: bool,
pub no_color: bool,
}
#[derive(Parser)]
#[command(name = "cred")]
#[command(about = "Local-first credential manager", long_about = None)]
pub struct Cli {
#[arg(long, global = true)]
pub json: bool,
#[arg(long, global = true)]
pub non_interactive: bool,
#[arg(long, global = true)]
pub dry_run: bool,
#[arg(long, short = 'y', global = true)]
pub yes: bool,
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
Init,
Doctor,
Target {
#[command(subcommand)]
action: TargetAction,
},
Secret {
#[command(subcommand)]
action: SecretAction,
},
Import(ImportArgs),
Export(ExportArgs),
Push(PushArgs),
Prune(PruneArgs),
Config {
#[command(subcommand)]
action: ConfigAction,
},
Project {
#[command(subcommand)]
action: ProjectAction,
},
}
#[derive(Args, Debug)]
pub struct PushArgs {
pub target: Target,
#[arg(num_args = 0..)]
pub keys: Vec<String>,
#[arg(long)]
pub repo: Option<String>,
}
#[derive(Args, Debug)]
pub struct PruneArgs {
pub target: Target,
#[arg(num_args = 0..)]
pub keys: Vec<String>,
#[arg(long)]
pub repo: Option<String>,
#[arg(long)]
pub all: bool,
}
#[derive(Subcommand, Debug)]
pub enum ConfigAction {
Get { key: String },
Set { key: String, value: String },
Unset { key: String },
List,
}
#[derive(Subcommand, Debug)]
pub enum ProjectAction {
Status,
}
#[derive(Subcommand, Debug)]
pub enum TargetAction {
Set(SetTargetArgs),
List,
Revoke {
name: Target,
},
}
#[derive(Args, Debug)]
pub struct SetTargetArgs {
pub name: Target,
#[arg(long)]
pub token: Option<String>,
}
#[derive(Subcommand, Debug)]
pub enum SecretAction {
Set {
key: String,
value: String,
#[arg(long, short = 'd')]
description: Option<String>,
#[arg(long, short = 'f')]
format: Option<SecretFormat>,
},
Get { key: String },
List {},
Describe {
key: String,
description: Option<String>,
},
Remove { key: String },
Revoke {
key: String,
#[arg(long)]
target: Target,
},
}
#[derive(Args, Debug)]
pub struct ImportArgs {
pub path: String,
#[arg(long)]
pub overwrite: bool,
}
#[derive(Args, Debug)]
pub struct ExportArgs {
pub path: String,
#[arg(long)]
pub force: bool,
}