From 8ae61871a3eba088bd24e5c6696bd0456373c663 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Wed, 7 Apr 2021 23:45:56 -0400 Subject: [PATCH] Actually use the clap dependency --- .github/workflows/ci.yml | 1 + src/main.rs | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45ea1bf..c26a82a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,4 +14,5 @@ jobs: extra_nix_config: | experimental-features = nix-command flakes - run: nix develop -c rustc --version + - run: nix run . -- ping - run: nix-build diff --git a/src/main.rs b/src/main.rs index 965f785..e5af86a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,6 @@ use std::fmt::{Display, Formatter}; +use clap::{App, SubCommand}; + enum VertDir { Up, @@ -107,11 +109,18 @@ impl Display for Game { } fn main () { - let mut game = Game::new(); - let sleep_duration = std::time::Duration::from_millis(33); - loop { - println!("{}", game); - game.step(); - std::thread::sleep(sleep_duration); + let matches = App::new("bouncy") + .version("1.0") + .subcommand(SubCommand::with_name("ping")).get_matches(); + if let Some(_matches) = matches.subcommand_matches("ping") { + println!("pong") + } else { + let mut game = Game::new(); + let sleep_duration = std::time::Duration::from_millis(33); + loop { + println!("{}", game); + game.step(); + std::thread::sleep(sleep_duration); + } } }