Skip to content
Snippets Groups Projects
cli.rs 1.53 KiB
Newer Older
use clap::{Args, Parser, Subcommand};
use std::path::PathBuf;

#[derive(Debug, Parser)]
#[command(author, version, about, long_about = None)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Command,
}

#[derive(Debug, Subcommand)]
pub enum Command {
    /// Check that firmware is well built
    CheckFile(CheckFileArgs),
    /// Flash firmware
    Flash(FlashArgs),
    /// Read the status of the program currently running, and
    /// check if there is a firmware installed if we are in
    /// bootloader mode.
    Status(StatusArgs),
}

#[derive(Args, Debug)]
pub struct CheckFileArgs {
    /// ELF file containing the firmware
    pub firmware: PathBuf,
}

#[derive(Args, Debug)]
pub struct CheckFlashArgs {
    /// ELF file containing the firmware
    pub firmware: PathBuf,
    /// I²C bus to use
    #[clap(short, long, default_value = "8")]
    pub i2c_bus: u8,
}

#[derive(Args, Debug)]
pub struct FlashArgs {
    /// Do not verify after flashing
    #[clap(long)]
    pub no_verify: bool,
    /// Do not program (verify only)
    #[clap(short, long, conflicts_with = "no_verify")]
    pub no_program: bool,
    /// I²C bus to use
    #[clap(short, long, default_value = "8")]
    pub i2c_bus: u8,
    /// ELF file containing the firmware
    pub firmware: PathBuf,
}

#[derive(Args, Debug)]
pub struct StatusArgs {
    /// I²C bus to use
    #[clap(short, long, default_value = "8")]
    pub i2c_bus: u8,
    /// Print only the running program, version, and extra arguments, separated by spaces
    #[clap(short, long)]
    pub short: bool,