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 5b574c8
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 7 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"] }
39 changes: 39 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use clap::{Args, Subcommand, Parser};

#[derive(Args)]
pub struct DaemonArgs {
}

#[derive(Parser)]
#[clap(name = "sand", about = "Command line countdown timers that don't take up a terminal.", version)]
pub struct Cli {
#[clap(subcommand)]
pub command: CliCommand,
}

#[derive(Subcommand)]
pub enum CliCommand {
/// 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
},

/// Launch the daemon
Daemon(DaemonArgs),
}
28 changes: 28 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::cli;

pub fn main(cmd: cli::CliCommand) {
match cmd {
cli::CliCommand::Start { duration } => {
let duration_str = duration.join(" ");
println!("Starting new timer for duration: {}", duration_str);
// Implement timer creation functionality
}
cli::CliCommand::Ls => {
println!("Listing timers...");
// Implement list functionality
}
cli::CliCommand::Pause { timer_id } => {
println!("Pausing timer {}...", timer_id);
// Implement pause functionality
}
cli::CliCommand::Resume { timer_id } => {
println!("Resuming timer {}...", timer_id);
// Implement resume functionality
}
cli::CliCommand::Cancel { timer_id } => {
println!("Cancelling timer {}...", timer_id);
// Implement cancel functionality
}
cli::CliCommand::Daemon(_) => unreachable!(),
}
}
6 changes: 6 additions & 0 deletions src/daemon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use crate::cli;

pub fn main(_args: cli::DaemonArgs) {
println!("Starting sand daemon ");
// Implement daemon functionality
}
19 changes: 12 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use std::env;
use clap::Parser;
use cli::CliCommand;

mod client;
mod daemon;
mod cli;

fn main() {
let cli = 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.command {
CliCommand::Daemon(args) => daemon::main(args),
_ => client::main(cli.command),
}
}

}
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 5b574c8

Please sign in to comment.