use clap::{Parser, Subcommand};
use chug_cli::{
action_builder::{ActionBuilder, BottleForestSnapshot},
tree::{display_tree, list_bottles},
};
#[derive(Parser)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Add {
bottles: Vec<String>,
},
Remove {
bottles: Vec<String>,
#[arg(long)]
all: bool,
},
Update,
List,
Tree,
}
fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
match cli.command {
Commands::Add { bottles } => {
let snapshot = BottleForestSnapshot::new()?;
ActionBuilder::new(&snapshot).add_bottles(&bottles)?.run()?;
}
Commands::Remove { all: true, bottles } => {
anyhow::ensure!(
bottles.is_empty(),
"Cannot specify bottles when --all is used",
);
let snapshot = BottleForestSnapshot::new()?;
ActionBuilder::new(&snapshot).remove_all().run()?;
}
Commands::Remove {
bottles,
all: false,
} => {
let snapshot = BottleForestSnapshot::new()?;
ActionBuilder::new(&snapshot)
.remove_bottles(&bottles)?
.run()?;
}
Commands::Update => {
let snapshot = BottleForestSnapshot::new()?;
ActionBuilder::new(&snapshot).update()?.run()?;
}
Commands::List => {
list_bottles()?;
}
Commands::Tree => {
display_tree()?;
}
}
Ok(())
}