use std::path::PathBuf;
use clap::{Args, Parser, Subcommand};
#[allow(unused_imports)]
use log::{debug, error, info, trace, warn};
use crate::ipc::IpcRequest;
use crate::search::SearchField;
#[derive(Clone, Debug, Parser)]
#[command(version)]
pub struct ShikaneCtl {
#[command(subcommand)]
pub(super) cmd: Command,
#[clap(long, short)]
pub(super) socket: Option<PathBuf>,
}
#[derive(Clone, Debug, Subcommand)]
pub enum Command {
#[clap(subcommand, alias = "dbg", hide = true)]
Debug(CmdDebug),
Switch(CmdSwitch),
Reload(CmdReload),
Export(CmdExport),
}
#[derive(Clone, Debug, Subcommand)]
pub enum CmdDebug {
CurrentState,
ListReports,
}
#[derive(Clone, Debug, Args)]
pub struct CmdSwitch {
name: String,
}
#[derive(Clone, Debug, Args)]
pub struct CmdReload {
file: Option<PathBuf>,
}
#[derive(Clone, Debug, Args)]
pub struct CmdExport {
#[command(flatten)]
pub search_fields: Option<IncludeSearchFields>,
pub profile_name: String,
}
#[derive(Clone, Debug, Parser)]
#[clap(group = clap::ArgGroup::new("include_search_fields").multiple(true))]
pub struct IncludeSearchFields {
#[arg(short, long, group = "include_search_fields")]
description: bool,
#[arg(short, long, group = "include_search_fields")]
name: bool,
#[arg(short, long, group = "include_search_fields")]
model: bool,
#[arg(short, long, group = "include_search_fields")]
serial: bool,
#[arg(short, long, group = "include_search_fields")]
vendor: bool,
}
impl Default for IncludeSearchFields {
fn default() -> Self {
Self {
description: false,
name: false,
model: true,
serial: true,
vendor: true,
}
}
}
impl From<IncludeSearchFields> for Vec<SearchField> {
fn from(value: IncludeSearchFields) -> Self {
let mut sf = vec![];
if value.description {
sf.push(SearchField::Description);
}
if value.name {
sf.push(SearchField::Name);
}
if value.model {
sf.push(SearchField::Model);
}
if value.serial {
sf.push(SearchField::Serial);
}
if value.vendor {
sf.push(SearchField::Vendor);
}
sf
}
}
impl From<Command> for IpcRequest {
fn from(cmd: Command) -> Self {
match cmd {
Command::Debug(c) => c.into(),
Command::Switch(c) => Self::SwitchProfile(c.name),
Command::Reload(c) => Self::ReloadConfig(c.file),
Command::Export(_) => Self::CurrentHeads,
}
}
}
impl From<CmdDebug> for IpcRequest {
fn from(value: CmdDebug) -> Self {
match value {
CmdDebug::CurrentState => Self::CurrentState,
CmdDebug::ListReports => Self::MatchReports,
}
}
}