From 2f154b391a85cf74e727d3714cf6a5c69ed300e2 Mon Sep 17 00:00:00 2001 From: random-geek <35757396+random-geek@users.noreply.github.com> Date: Sun, 24 Jan 2021 14:43:12 -0800 Subject: [PATCH] Remove unused enum bools --- src/cmd_line.rs | 43 +++++++++++++++++++--------------- src/commands/delete_objects.rs | 2 +- src/commands/fill.rs | 2 +- src/commands/replace_nodes.rs | 4 ++-- src/commands/set_param2.rs | 2 +- src/instance.rs | 6 ++--- 6 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/cmd_line.rs b/src/cmd_line.rs index a3d4c59..df01694 100644 --- a/src/cmd_line.rs +++ b/src/cmd_line.rs @@ -5,7 +5,7 @@ use clap::{App, Arg, SubCommand, AppSettings, crate_version, crate_authors}; use anyhow::Context; use crate::spatial::{Vec3, Area}; -use crate::instance::{ArgType, InstArgs}; +use crate::instance::{LogType, ArgType, InstArgs}; use crate::commands::{get_commands}; use crate::utils::fmt_duration; @@ -49,7 +49,6 @@ fn to_cmd_line_args<'a>(tup: &(ArgType, &'a str)) ]; } vec![match arg { - // TODO: Remove unused conditions here. ArgType::InputMapPath => Arg::with_name("input_map") .required(true) @@ -77,16 +76,11 @@ fn to_cmd_line_args<'a>(tup: &(ArgType, &'a str)) a } }, - ArgType::NewNode(req) => { - let a = Arg::with_name("new_node") - .required(req) - .help(help); - if !req { - a.long("newnode").takes_value(true) - } else { - a - } - }, + ArgType::NewNode => + Arg::with_name("new_node") + .takes_value(true) + .required(true) + .help(help), ArgType::Item => Arg::with_name("item") .takes_value(true) @@ -97,15 +91,14 @@ fn to_cmd_line_args<'a>(tup: &(ArgType, &'a str)) .takes_value(true) .required(true) .help(help), - ArgType::Param2Val(_) => + ArgType::Param2Val => Arg::with_name("param2_val") .required(true) .help(help), - ArgType::Object(req) => + ArgType::Object => Arg::with_name("object") .long("obj") .takes_value(true) - .required(req) .help(help), ArgType::Items => Arg::with_name("items") @@ -180,7 +173,8 @@ fn parse_cmd_line_args() -> anyhow::Result { item: sub_matches.value_of("item").map(str::to_string), new_item: sub_matches.value_of("new_item").map(str::to_string), param2_val: sub_matches.value_of("param2_val") - .map(|v| v.parse().unwrap()), + .map(|val| val.parse().context("Invalid param2 value.")) + .transpose().context("Invalid param2 value.")?, object: sub_matches.value_of("object").map(str::to_string), items: sub_matches.values_of("items") .map(|v| v.map(str::to_string).collect()), @@ -232,11 +226,22 @@ fn print_progress(done: usize, total: usize, real_start: Instant, } +fn print_log(log_type: LogType, msg: String) { + eprintln!("{}: {}", log_type, msg) +} + + pub fn run_cmd_line() { use std::sync::mpsc; use crate::instance::{InstState, InstEvent, spawn_compute_thread}; - let args = parse_cmd_line_args().unwrap(); + let args = match parse_cmd_line_args() { + Ok(a) => a, + Err(e) => { + print_log(LogType::Error, e.to_string()); + return; + } + }; let (handle, status) = spawn_compute_thread(args); const TICK: Duration = Duration::from_millis(25); @@ -278,7 +283,7 @@ pub fn run_cmd_line() { eprintln!(); } last_printed = InstState::Ignore; - eprintln!("{}: {}", log_type, msg); + print_log(log_type, msg); } }, Err(err) => { @@ -314,7 +319,7 @@ pub fn run_cmd_line() { } if last_printed != InstState::Ignore { - eprintln!(""); + eprintln!(); } let _ = handle.join(); diff --git a/src/commands/delete_objects.rs b/src/commands/delete_objects.rs index 71bfeec..1c4ecc8 100644 --- a/src/commands/delete_objects.rs +++ b/src/commands/delete_objects.rs @@ -107,7 +107,7 @@ pub fn get_command() -> Command { args: vec![ (ArgType::Area(false), "Area in which to delete objects"), (ArgType::Invert, "Delete all objects outside the area"), - (ArgType::Object(false), + (ArgType::Object, "Name of object to delete. If not specified, all objects will \ be deleted"), (ArgType::Items, diff --git a/src/commands/fill.rs b/src/commands/fill.rs index cca7688..8061229 100644 --- a/src/commands/fill.rs +++ b/src/commands/fill.rs @@ -72,7 +72,7 @@ pub fn get_command() -> Command { verify_args: None, args: vec![ (ArgType::Area(true), "Area to fill"), - (ArgType::NewNode(true), "Node to fill area with") + (ArgType::NewNode, "Name of node to fill area with") ], help: "Fill the entire area with one node." } diff --git a/src/commands/replace_nodes.rs b/src/commands/replace_nodes.rs index 43d7f8e..5e85d91 100644 --- a/src/commands/replace_nodes.rs +++ b/src/commands/replace_nodes.rs @@ -162,8 +162,8 @@ pub fn get_command() -> Command { func: replace_nodes, verify_args: Some(verify_args), args: vec![ - (ArgType::Node(true), "Node to replace"), - (ArgType::NewNode(true), "New node to replace with"), + (ArgType::Node(true), "Name of node to replace"), + (ArgType::NewNode, "Name of node to replace with"), (ArgType::Area(false), "Area in which to replace nodes"), (ArgType::Invert, "Replace nodes outside the given area") ], diff --git a/src/commands/set_param2.rs b/src/commands/set_param2.rs index a370d3d..b4c5077 100644 --- a/src/commands/set_param2.rs +++ b/src/commands/set_param2.rs @@ -115,7 +115,7 @@ pub fn get_command() -> Command { args: vec![ (ArgType::Area(false), "Area in which to set param2 values"), (ArgType::Node(false), "Node to set param2 values of"), - (ArgType::Param2Val(true), "New param2 value") + (ArgType::Param2Val, "New param2 value") ], help: "Set param2 values of an area or node." } diff --git a/src/instance.rs b/src/instance.rs index d2f1c97..aa28450 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -16,11 +16,11 @@ pub enum ArgType { Invert, Offset(bool), Node(bool), - NewNode(bool), + NewNode, Item, NewItem, - Param2Val(bool), - Object(bool), + Param2Val, + Object, Items, Key, Value,