geist_supervisor 0.1.28

Generic OTA supervisor for field devices
Documentation
use crate::app_config::SupervisorConfig;
use crate::cli::commands::{handle_command, Commands};
use anyhow::Result;
use clap::Parser;

pub mod commands;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
pub struct Cli {
    /// Which app to manage (required when multiple apps are configured)
    #[arg(long, global = true)]
    pub app: Option<String>,

    #[command(subcommand)]
    pub command: Option<Commands>,
}

impl Cli {
    pub fn run(self) -> Result<()> {
        match self.command {
            Some(cmd) => {
                let config = SupervisorConfig::load();
                let app_config = config
                    .resolve_app(self.app.as_deref())
                    .map_err(|e| anyhow::anyhow!("{}", e))?;
                handle_command(cmd, app_config)
            }
            None => {
                println!("No command provided. Use --help for usage information.");
                Ok(())
            }
        }
    }
}