mod commands;
mod crypto;
mod error;
mod git;
mod gpg;
mod key;
#[cfg(feature = "ssh")]
mod rage;
use clap::{Parser, Subcommand};
use error::Result;
use std::path::PathBuf;
#[derive(Parser)]
#[command(name = "git-crypt")]
#[command(version = "0.1.0")]
#[command(about = "Transparent file encryption in git", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Init,
Unlock {
#[arg(short, long)]
key_file: Option<PathBuf>,
},
Lock,
AddGpgUser {
gpg_id: String,
},
#[cfg(feature = "ssh")]
AddSshUser {
#[arg(long = "ssh-key", value_name = "SSH_KEY")]
ssh_key: PathBuf,
#[arg(short, long)]
alias: Option<String>,
},
ExportKey {
output: PathBuf,
},
ImportKey {
input: PathBuf,
},
#[cfg(feature = "ssh")]
ImportAgeKey {
#[arg(long = "input", value_name = "AGE_FILE")]
input: PathBuf,
#[arg(long = "identity", value_name = "SSH_KEY")]
identity: PathBuf,
},
Clean,
Smudge,
Diff,
Status,
}
fn main() {
if let Err(e) = run() {
eprintln!("Error: {}", e);
std::process::exit(1);
}
}
fn run() -> Result<()> {
let cli = Cli::parse();
match cli.command {
Commands::Init => commands::init(),
Commands::Unlock { key_file } => commands::unlock(key_file.as_deref()),
Commands::Lock => commands::lock(),
Commands::AddGpgUser { gpg_id } => commands::add_gpg_user(&gpg_id),
#[cfg(feature = "ssh")]
Commands::AddSshUser { ssh_key, alias } => {
commands::add_ssh_user(&ssh_key, alias.as_deref())
}
Commands::ExportKey { output } => commands::export_key(&output),
Commands::ImportKey { input } => commands::import_key(&input),
#[cfg(feature = "ssh")]
Commands::ImportAgeKey { input, identity } => commands::import_age_key(&input, &identity),
Commands::Clean => commands::clean(),
Commands::Smudge => commands::smudge(),
Commands::Diff => commands::diff(),
Commands::Status => {
println!("Status command not yet implemented");
Ok(())
}
}
}