-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
starting creating structure, add clap
- Loading branch information
Showing
6 changed files
with
329 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ version = "0.1.0" | |
edition = "2021" | ||
|
||
[dependencies] | ||
clap = { version = "4.5.13", features = ["derive"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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... |