use crate::args::CommandTrait;
use clap::{Args, Subcommand};
use enum_dispatch::enum_dispatch;
#[derive(Debug, Args)]
pub struct UpdateArgs {
#[command(subcommand)]
pub command: UpdateCommands,
}
impl CommandTrait for UpdateArgs {
fn requires_device(&self) -> bool {
self.command.requires_device()
}
}
#[enum_dispatch(CommandTrait)]
#[derive(Debug, Subcommand)]
pub enum UpdateCommands {
Slot(UpdateSlotArgs),
Commit(UpdateCommitArgs),
#[command(hide = true)]
Otp(UpdateOtpArgs),
}
#[derive(Debug, Args)]
pub struct UpdateSlotArgs {
#[arg(long, short = 'l', value_name = "INDEX", required = true)]
pub slot: u8,
#[arg(long, short = 'm', value_name = "FILE", required = true)]
pub image: String,
}
impl CommandTrait for UpdateSlotArgs {
fn requires_device(&self) -> bool {
true
}
}
#[derive(Debug, Args)]
pub struct UpdateCommitArgs {
#[arg(long, short = 'l', value_name = "INDEX")]
pub slot: Option<u8>,
}
impl CommandTrait for UpdateCommitArgs {
fn requires_device(&self) -> bool {
true
}
}
#[derive(Debug, Args)]
pub struct UpdateOtpArgs {
#[arg(long, conflicts_with = "write")]
pub read: bool,
#[arg(long, value_name = "ROW=VALUE", conflicts_with = "read")]
pub write: Option<String>,
}
impl CommandTrait for UpdateOtpArgs {
fn requires_device(&self) -> bool {
true
}
}