use crate::exit_code::ExitCode;
use clap::Parser;
use efivar::VarManager;
use crate::id::BootEntryId;
use self::{next::BootNextCommand, order::OrderCommand};
pub mod add;
pub mod delete;
pub mod enable_disable;
pub mod get_entries;
pub mod next;
pub mod order;
pub mod partition;
#[cfg(test)]
mod tests;
#[derive(Parser)]
pub enum BootCommand {
GetEntries {
#[arg(short, long)]
verbose: bool,
},
Add {
#[arg(short, long)]
partition: Option<String>,
#[arg(short, long)]
file: String,
#[arg(short, long, alias = "desc")]
description: String,
#[arg(long)]
force: bool,
#[arg(long)]
id: Option<BootEntryId>,
},
#[command(alias = "del")]
#[command(alias = "remove")]
Delete {
#[arg()]
id: BootEntryId,
},
Enable {
#[arg()]
id: BootEntryId,
},
Disable {
#[arg()]
id: BootEntryId,
},
#[command(subcommand)]
Order(OrderCommand),
#[command(subcommand)]
Next(BootNextCommand),
}
pub fn run(manager: &mut dyn VarManager, cmd: BootCommand) -> ExitCode {
match cmd {
BootCommand::GetEntries { verbose } => get_entries::run(manager, verbose),
BootCommand::Add {
partition,
file,
description,
force,
id,
} => add::run(
manager,
partition,
file,
description,
force,
id.map(|id| id.0),
),
BootCommand::Delete { id } => delete::run(manager, id.0),
BootCommand::Enable { id } => enable_disable::enable(manager, id.0),
BootCommand::Disable { id } => enable_disable::disable(manager, id.0),
BootCommand::Order(arg) => order::run(manager, arg),
BootCommand::Next(arg) => next::run(manager, arg),
}
}