aboutsummaryrefslogtreecommitdiff
path: root/karlc/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'karlc/src/main.rs')
-rw-r--r--karlc/src/main.rs60
1 files changed, 53 insertions, 7 deletions
diff --git a/karlc/src/main.rs b/karlc/src/main.rs
index 8db8d18..bfd433e 100644
--- a/karlc/src/main.rs
+++ b/karlc/src/main.rs
@@ -1,18 +1,64 @@
-use std::os::unix::net::UnixStream;
+pub mod client;
+pub mod pretty;
-use clap::Parser;
-use karlcommon::socket_path;
+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};
/// CLI interface for karld
#[derive(Parser)]
#[clap(about, author, version)]
-struct Args {}
+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() {
- let _args = Args::parse();
+ env_logger::init();
+ let args = Args::parse();
- let socket = UnixStream::connect(socket_path()).unwrap();
+ 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!("{:?}", t)
+ }
+ }
+ }
+ }
}