From fe40316b2c02f421b65708c08fa3270b20ad78f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 20 Aug 2022 11:30:00 +0200 Subject: [PATCH] args: --no-recording argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/args.rs | 6 +++++- src/main.rs | 12 ++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/args.rs b/src/args.rs index 74bea13..5361019 100644 --- a/src/args.rs +++ b/src/args.rs @@ -14,7 +14,7 @@ // along with this program. If not, see . use crate::types::Variant; -use clap::Parser; +use clap::{ArgAction, Parser}; use std::default::Default; #[derive(Parser, Debug)] @@ -27,4 +27,8 @@ pub struct Args { /// Game variant. Unused #[clap(arg_enum, short, long, default_value_t = Default::default())] pub variant: Variant, + + /// Recording + #[clap(name = "no-recording", long, action = ArgAction::SetFalse, default_value_t = true)] + pub recording: bool, } diff --git a/src/main.rs b/src/main.rs index 34f2bc0..549004e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,10 +71,12 @@ fn main() -> Result<(), Error> { args.players, dt.format("%Y-%m-%d_%H:%M:%S") ); - println!("Recording at: {}", filename); + if args.recording { + println!("Recording at: {}", filename); - // TODO: Move writing to GameState - write_header(filename.clone().as_str(), args.players, vec![args.variant])?; + // TODO: Move writing to GameState + write_header(filename.clone().as_str(), args.players, vec![args.variant])?; + } let mut rl = Editor::<()>::new()?; let mut game: GameState = GameState::new(args.players, vec![args.variant]); @@ -89,7 +91,9 @@ fn main() -> Result<(), Error> { Action::Game(action) => { game.add_action(action.clone()); // TODO: Move writing to GameState - write_actions(filename.clone().as_str(), action)? + if args.recording { + write_actions(filename.clone().as_str(), action)? + } } Action::Repl(ReplAction::DisplayBoard) => game.show(), _ => (),