Remove unused enum bools

master
random-geek 2021-01-24 14:43:12 -08:00
parent 056368b412
commit 2f154b391a
6 changed files with 32 additions and 27 deletions

View File

@ -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<InstArgs> {
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();

View File

@ -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,

View File

@ -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."
}

View File

@ -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")
],

View File

@ -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."
}

View File

@ -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,