use alttabway::{
daemon::Daemon,
ipc::{AlttabwayIpc, Direction, IpcCommand, Modifier},
};
use clap::{ArgGroup, Parser, Subcommand};
#[derive(Parser)]
#[command(version, about, long_about = None)]
#[command(propagate_version = true)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Daemon,
#[command(group(ArgGroup::new("direction").args(["next", "previous"])))]
Show {
#[arg(long)]
next: bool,
#[arg(long)]
previous: bool,
#[arg(long, value_enum, default_values_t = Daemon::DEFAULT_REQ_MODIFIER, value_delimiter = ',')]
modifiers_held: Vec<Modifier>,
},
}
#[tokio::main(flavor = "multi_thread")]
async fn main() {
tracing_subscriber::fmt::init();
let cli = Cli::parse();
match &cli.command {
Commands::Daemon => {
tracing::debug!("requesting daemon start");
if let Err(err) = Daemon::start().await {
tracing::info!("Exiting: {}", err);
}
}
Commands::Show {
next,
previous,
modifiers_held,
} => {
let direction = if *next {
Some(Direction::Next)
} else if *previous {
Some(Direction::Previous)
} else {
None
};
tracing::debug!("Modifiers required to be held: {:?}", modifiers_held);
match AlttabwayIpc::send_command(IpcCommand::Show {
direction,
modifiers: modifiers_held.clone(),
})
.await
{
Ok(response) => tracing::info!("{:?}", response),
Err(err) => tracing::warn!(
"Please check if the alttabway daemon is running. Error: {}",
err
),
}
}
}
}