pub mod client; pub mod pretty; use std::{os::unix::net::UnixStream, process::exit}; use clap::{Parser, Subcommand}; use client::Client; use karlcommon::{socket_path, version, ClientboundPacket, ServerboundPacket}; use log::{error, info}; use crate::pretty::Pretty; /// CLI interface for karld #[derive(Parser)] #[clap(about, author, version)] struct Args { #[clap(subcommand)] action: Action, } #[derive(Subcommand)] pub enum Action { /// Show version of the client and daemon Version, /// List all taskss ListTasks, } fn main() { env_logger::init(); let args = Args::parse(); let socket = match UnixStream::connect(socket_path()) { Ok(s) => s, Err(e) => { error!("failed to connect to socket: {}", e); exit(1); } }; let mut client = Client::new(socket); info!("connected"); let handshake = client.receiver.recv().unwrap(); match args.action { Action::Version => { if let ClientboundPacket::Handshake { version: daemon_version, } = handshake { println!("{}", version!()); println!("{daemon_version}"); } else { error!("handshake is not the first packet") } } Action::ListTasks => { client.send(ServerboundPacket::Download); if let ClientboundPacket::DownloadResponse(tasks) = client.receiver.recv().unwrap() { for t in tasks { println!("{}", Pretty(t)) } } } } }