use anyhow::Result;
use clap::CommandFactory;
use clap::Parser;
use clap_complete::Shell;
use std::io;
pub const DEFAULT_MAX_PILE_SIZE: usize = 1 << 44;
mod cli;
use cli::branch::BranchCommand;
use cli::pile::PileCommand;
use cli::store::StoreCommand;
#[derive(Parser)]
enum TribleCli {
Genid,
Completion {
#[arg(value_enum)]
shell: Shell,
},
Branch {
#[command(subcommand)]
cmd: BranchCommand,
},
Pile {
#[command(subcommand)]
cmd: PileCommand,
},
Store {
#[command(subcommand)]
cmd: StoreCommand,
},
}
fn main() -> Result<()> {
let args = TribleCli::parse();
match args {
TribleCli::Genid => {
let mut id = [0u8; 16];
getrandom::fill(&mut id)?;
let encoded_id = hex::encode(id);
println!("{}", encoded_id.to_ascii_uppercase());
}
TribleCli::Completion { shell } => {
let mut cmd = TribleCli::command();
let bin_name = cmd.get_name().to_string();
clap_complete::generate(shell, &mut cmd, bin_name, &mut io::stdout());
}
TribleCli::Branch { cmd } => cli::branch::run(cmd)?,
TribleCli::Pile { cmd } => cli::pile::run(cmd)?,
TribleCli::Store { cmd } => cli::store::run(cmd)?,
}
Ok(())
}