kraven 0.3.0

Manage named environment variable profiles
//! kraven - Manage named environment variable profiles.

use anyhow::Result;
use clap::{Parser, Subcommand};

mod commands;
mod completions;
mod config;
mod profile;

/// CLI for managing named environment variable profiles.
#[derive(Parser)]
#[command(name = "kraven")]
#[command(author, version, about = "Manage named environment variable profiles")]
#[command(arg_required_else_help = true)]
pub struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    /// Activate a profile (spawn a subshell with the profile's env vars)
    Activate {
        /// Name of the profile to activate
        profile: String,
    },

    /// Show how to exit the current kraven session
    Deactivate,

    /// List available profiles
    #[command(visible_alias = "ls")]
    List,

    /// Create or edit a profile using $EDITOR
    Edit {
        /// Name of the profile to edit
        profile: String,
    },

    /// Display profile contents
    Show {
        /// Name of the profile to show
        profile: String,

        /// Mask sensitive values
        #[arg(short, long)]
        mask: bool,
    },

    /// Remove a profile
    #[command(visible_alias = "rm")]
    Remove {
        /// Name of the profile to remove
        profile: String,

        /// Skip confirmation prompt
        #[arg(short, long)]
        force: bool,
    },

    /// Encrypt a profile with GPG
    Encrypt {
        /// Name of the profile to encrypt
        profile: String,
    },

    /// Decrypt a GPG-encrypted profile
    Decrypt {
        /// Name of the profile to decrypt
        profile: String,
    },

    /// Show the currently active profile
    Current,

    /// Print shell completion setup instructions
    Completions,
}

fn main() -> Result<()> {
    completions::init();

    let cli = Cli::parse();

    match cli.command {
        Commands::Activate { profile } => commands::activate::run(&profile),
        Commands::Deactivate => commands::deactivate::run(),
        Commands::List => commands::list::run(),
        Commands::Edit { profile } => commands::edit::run(&profile),
        Commands::Show { profile, mask } => commands::show::run(&profile, mask),
        Commands::Remove { profile, force } => commands::remove::run(&profile, force),
        Commands::Encrypt { profile } => commands::encrypt::run(&profile),
        Commands::Decrypt { profile } => commands::decrypt::run(&profile),
        Commands::Current => commands::current::run(),
        Commands::Completions => commands::completions::run(),
    }
}