Skip to content

Commit

Permalink
starting creating structure, add clap
Browse files Browse the repository at this point in the history
  • Loading branch information
sullyj3 committed Aug 5, 2024
1 parent f06fd75 commit f1c5459
Show file tree
Hide file tree
Showing 6 changed files with 329 additions and 6 deletions.
230 changes: 230 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ version = "0.1.0"
edition = "2021"

[dependencies]
clap = { version = "4.5.13", features = ["derive"] }
58 changes: 58 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use clap::{Args, Subcommand};

#[derive(Args)]
pub struct ClientArgs {
#[clap(subcommand)]
pub command: ClientCommands,
}

#[derive(Subcommand)]
pub enum ClientCommands {
/// Start a new timer for the given duration
Start {
#[clap(name = "DURATION", num_args = 1.., value_delimiter = ' ')]
duration: Vec<String>,
},
/// List active timers
#[clap(alias = "list")]
Ls,
/// Pause the timer with the given ID
Pause {
timer_id: String
},
/// Resume the timer with the given ID
Resume {
timer_id: String
},
/// Cancel the timer with the given ID
Cancel {
timer_id: String
},
}

pub fn main(args: ClientArgs) {
match args.command {
ClientCommands::Start { duration } => {
let duration_str = duration.join(" ");
println!("Starting new timer for duration: {}", duration_str);
// Implement timer creation functionality
}
ClientCommands::Ls => {
println!("Listing timers...");
// Implement list functionality
}
ClientCommands::Pause { timer_id } => {
println!("Pausing timer {}...", timer_id);
// Implement pause functionality
}
ClientCommands::Resume { timer_id } => {
println!("Resuming timer {}...", timer_id);
// Implement resume functionality
}
ClientCommands::Cancel { timer_id } => {
println!("Cancelling timer {}...", timer_id);
// Implement cancel functionality
}
}
}

13 changes: 13 additions & 0 deletions src/daemon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use clap::Args;

#[derive(Args)]
pub struct DaemonArgs {
/// Port to listen on
#[clap(short, long, default_value = "8080")]
port: u16,
}

pub fn main(args: DaemonArgs) {
println!("Starting sand daemon on port {}...", args.port);
// Implement daemon functionality
}
24 changes: 18 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
use std::env;
use clap::Parser;

mod client;
mod daemon;
mod sand;

#[derive(Parser)]
#[clap(name = "sand", about = "A simple timer CLI and daemon", version)]
enum Cli {
/// Run the client
Client(client::ClientArgs),
/// Run the daemon
Daemon(daemon::DaemonArgs),
}

fn main() {
let cli = Cli::parse();

let args: Vec<String> = env::args().collect();
if args.len() > 1 && args[1] == "version" {
println!("Sand v0.3.0: rewrite it in Rust");
} else {
println!("Hello, world!");
match cli {
Cli::Client(args) => client::main(args),
Cli::Daemon(args) => daemon::main(args),
}
}
9 changes: 9 additions & 0 deletions src/sand.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This module will contain common functionality and message wire format

pub enum Message {
// Define your message types here
}

// Implement serialization/deserialization for Message

// Other common functionality...

0 comments on commit f1c5459

Please sign in to comment.