summaryrefslogtreecommitdiffstats
path: root/CLI/rust/src
diff options
context:
space:
mode:
authora14m <[email protected]>2021-03-31 23:52:46 +0200
committera14m <[email protected]>2021-04-01 00:39:42 +0200
commit7faaaff2ab17a2571117e4ba93aa2139b2ddb376 (patch)
tree72b9b73290a1137507a0612d8b23df8716276c82 /CLI/rust/src
parent465c4e2301ec9dc58a1b204791a37bcf7a1cd9bd (diff)
Add the CLI options basic args
Add the ordering for the help menu Define the CLI options of clap
Diffstat (limited to 'CLI/rust/src')
-rw-r--r--CLI/rust/src/game_of_life.rs69
-rw-r--r--CLI/rust/src/main.rs5
2 files changed, 73 insertions, 1 deletions
diff --git a/CLI/rust/src/game_of_life.rs b/CLI/rust/src/game_of_life.rs
new file mode 100644
index 0000000..fffaa42
--- /dev/null
+++ b/CLI/rust/src/game_of_life.rs
@@ -0,0 +1,69 @@
+use clap::{crate_authors, crate_version, App, Arg, ArgMatches, Error};
+
+/// Define the Clap CLI for running Game of Life simulation
+///
+/// Using Clap to define the available options that can be used with game of life
+pub(crate) fn options() -> Result<ArgMatches, Error> {
+ let matches = App::new("Game of Life")
+ .author(crate_authors!())
+ .version(crate_version!())
+ .arg(
+ Arg::new("seed")
+ .about("Specify the seed number to use as an initial state [default: random]")
+ .takes_value(true)
+ .long("seed")
+ .short('s')
+ .conflicts_with("input")
+ .display_order(0)
+ )
+ .arg(
+ Arg::new("input")
+ .about("Specify the path/URL for the file to use as an initial state. (used instead of seed)")
+ .takes_value(true)
+ .long("input")
+ .short('i')
+ .display_order(1)
+ )
+ .arg(
+ Arg::new("width")
+ .about("Specify the width of generated universe. [default: terminal width]")
+ .takes_value(true)
+ .long("width")
+ .display_order(2)
+ )
+ .arg(
+ Arg::new("height")
+ .about("Specify the width of generated universe. [default: terminal height]")
+ .takes_value(true)
+ .long("height")
+ .display_order(3)
+ )
+ .arg(
+ Arg::new("live-cell")
+ .about("Specify the live-cell representation")
+ .takes_value(true)
+ .long("live-cell")
+ .default_value("█")
+ .display_order(4)
+ )
+ .arg(
+ Arg::new("dead-cell")
+ .about("Specify the dead-cell representation")
+ .takes_value(true)
+ .long("dead-cell")
+ .default_value(" ")
+ .display_order(5)
+ )
+ .arg(
+ Arg::new("delay")
+ .about("Specify the introduced delay between each generation")
+ .takes_value(true)
+ .short('d')
+ .long("delay")
+ .default_value("50")
+ .display_order(6)
+ )
+ .get_matches();
+
+ Ok(matches)
+}
diff --git a/CLI/rust/src/main.rs b/CLI/rust/src/main.rs
index e7a11a9..71f81e5 100644
--- a/CLI/rust/src/main.rs
+++ b/CLI/rust/src/main.rs
@@ -1,3 +1,6 @@
+mod game_of_life;
+
fn main() {
- println!("Hello, world!");
+ let matches = game_of_life::options().unwrap_or_else(|e| e.exit());
+ println!("{:?}", matches);
}