refactor(blahctl)!: push down desc_file argument

This commit is contained in:
oxalica 2024-09-19 00:00:32 -04:00
parent a04bff9f2f
commit 25936cc4f7

View file

@ -32,10 +32,6 @@ struct Cli {
enum Command { enum Command {
/// Identity management. /// Identity management.
Identity { Identity {
/// The identity description JSON file to write or modify.
#[arg(long, short = 'f')]
desc_file: PathBuf,
#[command(subcommand)] #[command(subcommand)]
command: IdCommand, command: IdCommand,
}, },
@ -63,6 +59,10 @@ enum Command {
enum IdCommand { enum IdCommand {
/// Generate a new identity keypair. /// Generate a new identity keypair.
Generate { Generate {
/// The identity description JSON file to write.
#[arg(long, short = 'f')]
desc_file: PathBuf,
/// The output path to save the generated signing (private) key. /// The output path to save the generated signing (private) key.
/// Keep it secret and safe! /// Keep it secret and safe!
#[arg(long)] #[arg(long)]
@ -78,6 +78,10 @@ enum IdCommand {
}, },
/// Add an action subkey to an existing identity description. /// Add an action subkey to an existing identity description.
AddActKey { AddActKey {
/// The identity description JSON file to modify.
#[arg(long, short = 'f')]
desc_file: PathBuf,
/// The identity signing (private) key to sign with. /// The identity signing (private) key to sign with.
#[arg(long)] #[arg(long)]
id_key_file: PathBuf, id_key_file: PathBuf,
@ -190,7 +194,7 @@ fn main() -> Result<()> {
let cli = <Cli as clap::Parser>::parse(); let cli = <Cli as clap::Parser>::parse();
match cli.command { match cli.command {
Command::Identity { desc_file, command } => main_id(desc_file, command)?, Command::Identity { command } => main_id(command)?,
Command::Database { database, command } => { Command::Database { database, command } => {
use rusqlite::OpenFlags; use rusqlite::OpenFlags;
@ -216,9 +220,10 @@ fn build_rt() -> Result<Runtime> {
.context("failed to initialize tokio runtime") .context("failed to initialize tokio runtime")
} }
fn main_id(desc_file: PathBuf, cmd: IdCommand) -> Result<()> { fn main_id(cmd: IdCommand) -> Result<()> {
match cmd { match cmd {
IdCommand::Generate { IdCommand::Generate {
desc_file,
id_key_file, id_key_file,
id_url, id_url,
} => { } => {
@ -251,6 +256,7 @@ fn main_id(desc_file: PathBuf, cmd: IdCommand) -> Result<()> {
fs::write(desc_file, &id_desc_str).context("failed to save identity description")?; fs::write(desc_file, &id_desc_str).context("failed to save identity description")?;
} }
IdCommand::AddActKey { IdCommand::AddActKey {
desc_file,
id_key_file, id_key_file,
act_key, act_key,
expire, expire,