converted inv_costing_from_cmd_arg return type to a result; resolves #9
This commit is contained in:
parent
fda794b24b
commit
6b179ec976
|
@ -89,7 +89,7 @@ name = "bstr"
|
||||||
version = "0.2.7"
|
version = "0.2.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex-automata 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex-automata 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -164,7 +164,7 @@ version = "0.6.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -275,7 +275,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy_static"
|
name = "lazy_static"
|
||||||
version = "1.3.0"
|
version = "1.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -580,7 +580,7 @@ name = "thread_local"
|
||||||
version = "0.3.6"
|
version = "0.3.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -679,7 +679,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
|
||||||
"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
|
"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
|
||||||
"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f"
|
"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f"
|
||||||
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
|
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
"checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba"
|
"checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba"
|
||||||
"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
|
"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
|
||||||
"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
|
"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
|
||||||
|
|
|
@ -142,25 +142,19 @@ pub fn choose_inventory_costing_method() -> InventoryCostingMethod {
|
||||||
|
|
||||||
method
|
method
|
||||||
}
|
}
|
||||||
pub fn inv_costing_from_cmd_arg(arg: String) -> InventoryCostingMethod {
|
pub fn inv_costing_from_cmd_arg(arg: String) -> Result<(InventoryCostingMethod), &'static str> {
|
||||||
|
|
||||||
let method = match _costing_method(arg) {
|
match arg.trim() { // Without .trim(), there's a hidden \n or something preventing the match
|
||||||
Ok(x) => {x},
|
"1" => Ok(InventoryCostingMethod::LIFObyLotCreationDate),
|
||||||
Err(err) => { process::exit(1) }
|
"2" => Ok(InventoryCostingMethod::LIFObyLotBasisDate),
|
||||||
};
|
"3" => Ok(InventoryCostingMethod::FIFObyLotCreationDate),
|
||||||
|
"4" => Ok(InventoryCostingMethod::FIFObyLotBasisDate),
|
||||||
fn _costing_method(input: String) -> Result<(InventoryCostingMethod), Box<Error>> {
|
_ => {
|
||||||
|
println!("Invalid choice. Please enter a valid number.");
|
||||||
match input.trim() { // Without .trim(), there's a hidden \n or something preventing the match
|
return Err("Invalid choice");
|
||||||
"1" => Ok(InventoryCostingMethod::LIFObyLotCreationDate),
|
|
||||||
"2" => Ok(InventoryCostingMethod::LIFObyLotBasisDate),
|
|
||||||
"3" => Ok(InventoryCostingMethod::FIFObyLotCreationDate),
|
|
||||||
"4" => Ok(InventoryCostingMethod::FIFObyLotBasisDate),
|
|
||||||
_ => { println!("Invalid choice. Please enter a valid number."); _costing_method(input) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
method
|
|
||||||
}
|
}
|
||||||
pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> (bool, String) {
|
pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> (bool, String) {
|
||||||
let election: bool;
|
let election: bool;
|
||||||
|
|
|
@ -232,7 +232,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
_ => { println!("Invalid choice for inventory costing method. Exiting."); process::exit(0); }
|
_ => { println!("Invalid choice for inventory costing method. Exiting."); process::exit(0); }
|
||||||
}
|
}
|
||||||
|
|
||||||
let costing_method_choice = cli_user_choices::inv_costing_from_cmd_arg(args.inv_costing_method.into_string().unwrap());
|
let costing_method_choice_r = cli_user_choices::inv_costing_from_cmd_arg(args.inv_costing_method.into_string().unwrap());
|
||||||
|
if costing_method_choice_r.is_err() {
|
||||||
|
process::exit(1)
|
||||||
|
}
|
||||||
|
let costing_method_choice = costing_method_choice_r.unwrap();
|
||||||
|
|
||||||
settings = ImportProcessParameters {
|
settings = ImportProcessParameters {
|
||||||
export_path: output_dir_path,
|
export_path: output_dir_path,
|
||||||
|
|
Loading…
Reference in New Issue