-
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
7 changed files
with
325 additions
and
7 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,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), | ||
} |
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,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!(), | ||
} | ||
} |
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,6 @@ | ||
use crate::cli; | ||
|
||
pub fn main(_args: cli::DaemonArgs) { | ||
println!("Starting sand daemon "); | ||
// 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,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), | ||
} | ||
} | ||
|
||
} |
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... |