Files
wara/src/config/cli.rs
2026-07-03 19:10:57 +03:00

112 lines
2.5 KiB
Rust

/*
* Copyright (c) 2026 MCorange.
* All rights reserved.
*
* Unauthorized copying, modification, distribution, or use of this
* software, in whole or in part, is prohibited without prior written
* permission.
*/
use clap::ArgGroup;
use serde::de;
#[derive(Debug, Clone, clap::Parser, Default)]
#[command(
author = env!("CARGO_PKG_AUTHORS"),
version,
after_help = concat!(
"Made by: ", env!("CARGO_PKG_AUTHORS"), "\n",
"All Rights Reserved"
)
)]
pub struct CliArgs {
/// Configuration file path
#[arg(long = "config", short = 'C', default_value = "./config.toml")]
pub config_file: camino::Utf8PathBuf,
/// Output more information in logs
#[arg(long = "verbose", short = 'v')]
pub verbose: bool,
#[command(subcommand)]
pub command: CliCommand,
}
#[derive(Debug, Clone, clap::Subcommand, Default)]
pub enum CliCommand {
/// Run command once
#[command(
group(
ArgGroup::new("devs")
.args(["all", "devices"])
.required(true)
)
)]
Run {
/// Run on ALL devices
#[arg(long, short = 'a')]
all: bool,
/// Run on all specified devices
#[arg(long, short = 'd')]
devices: Vec<String>,
/// Command to run
#[arg(long, short = 'c')]
command: String,
/// Output format
#[arg(long, short = 'f')]
format: OutputFormat,
},
/// Run command continuosly
#[command(
group(
ArgGroup::new("devs")
.args(["all", "devices"])
.required(true)
)
)]
Monitor {
/// Run on ALL devices
#[arg(long, short = 'a')]
all: bool,
/// Run on all specified devices
#[arg(long, short = 'd')]
devices: Vec<String>,
/// Command to run
#[arg(long, short = 'c')]
command: String,
/// Output format
#[arg(long, short = 'f')]
format: OutputFormat,
/// Interval to run the commands at
#[arg(long, short = 'i')]
interval: f32,
},
/// Manage devices
Device {
#[command(subcommand)]
command: CliDeviceCommand,
},
#[default]
#[clap(skip)]
None,
}
#[derive(Debug, Clone, clap::Subcommand, Default)]
pub enum CliDeviceCommand {
/// List devices
List,
#[default]
#[clap(skip)]
None,
}
#[derive(Clone, Debug, Default, clap::ValueEnum)]
pub enum OutputFormat {
#[default]
Csv,
Table,
Json,
}