Inv_costing_method arg now passed through wizard. Related refactoring.
This commit is contained in:
parent
ea0c42089f
commit
6440f0e47f
|
@ -5,6 +5,7 @@ use std::error::Error;
|
|||
use std::io::{self, BufRead};
|
||||
use std::process;
|
||||
use std::path::PathBuf;
|
||||
use std::ffi::OsString;
|
||||
|
||||
use chrono::NaiveDate;
|
||||
use rustyline::completion::{Completer, FilenameCompleter, Pair};
|
||||
|
@ -128,44 +129,47 @@ fn _get_path() -> Result<(String, bool), Box<dyn Error>> {
|
|||
// }
|
||||
// }
|
||||
|
||||
pub fn choose_inventory_costing_method() -> Result<InventoryCostingMethod, Box<dyn Error>> {
|
||||
pub fn choose_inventory_costing_method(cmd_line_arg: OsString) -> Result<InventoryCostingMethod, Box<dyn Error>> {
|
||||
|
||||
println!("Choose the lot inventory costing method. [Default: 1]");
|
||||
println!("Choose the lot inventory costing method. [Default/Chosen: {:?}]", cmd_line_arg);
|
||||
println!("1. LIFO according to the order the lot was created.");
|
||||
println!("2. LIFO according to the basis date of the lot.");
|
||||
println!("3. FIFO according to the order the lot was created.");
|
||||
println!("4. FIFO according to the basis date of the lot.");
|
||||
|
||||
let method = _costing_method()?;
|
||||
let method = _costing_method(cmd_line_arg)?;
|
||||
|
||||
fn _costing_method() -> Result<InventoryCostingMethod, Box<dyn Error>> {
|
||||
fn _costing_method(cmd_line_arg: OsString) -> Result<InventoryCostingMethod, Box<dyn Error>> {
|
||||
|
||||
let mut input = String::new();
|
||||
let stdin = io::stdin();
|
||||
stdin.lock().read_line(&mut input).expect("Failed to read stdin");
|
||||
|
||||
match input.trim() { // Without .trim(), there's a hidden \n or something preventing the match
|
||||
"1" | "" => Ok(InventoryCostingMethod::LIFObyLotCreationDate),
|
||||
"" => Ok(inv_costing_from_cmd_arg(cmd_line_arg)?),
|
||||
"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() }
|
||||
_ => { println!("Invalid choice. Please enter a valid choice."); _costing_method(cmd_line_arg) }
|
||||
}
|
||||
}
|
||||
|
||||
Ok(method)
|
||||
}
|
||||
pub fn inv_costing_from_cmd_arg(arg: String) -> Result<InventoryCostingMethod, &'static str> {
|
||||
pub fn inv_costing_from_cmd_arg(arg: OsString) -> Result<InventoryCostingMethod, &'static str> {
|
||||
|
||||
match arg.trim() { // Without .trim(), there's a hidden \n or something preventing the match
|
||||
let inv_costing_arg = match arg.into_string().expect("Could not convert OsString to String.").trim() {
|
||||
"1" => {"1"} "2" => {"2"} "3" => {"3"} "4" => {"4"}
|
||||
_ => { println!("WARN: Invalid command line arg passed for 'inv_costing_method'. Using default."); "1" }
|
||||
};
|
||||
|
||||
match inv_costing_arg {
|
||||
"1" => Ok(InventoryCostingMethod::LIFObyLotCreationDate),
|
||||
"2" => Ok(InventoryCostingMethod::LIFObyLotBasisDate),
|
||||
"3" => Ok(InventoryCostingMethod::FIFObyLotCreationDate),
|
||||
"4" => Ok(InventoryCostingMethod::FIFObyLotBasisDate),
|
||||
_ => {
|
||||
println!("Invalid choice. Please enter a valid number.");
|
||||
return Err("Invalid choice");
|
||||
}
|
||||
_ => { Err("Invalid input parameter") } // Impossible code path
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,13 +44,7 @@ pub(crate) fn skip_wizard(args: super::Cli) -> Result<(
|
|||
like_kind_cutoff_date_string = "1-1-1".to_string();
|
||||
};
|
||||
|
||||
let clean_inv_costing_arg = match args.inv_costing_method.clone().into_string().expect("Invalid choice on costing method. Aborting.").trim() {
|
||||
"1" => {"1"} "2" => {"2"} "3" => {"3"} "4" => {"4"}
|
||||
_ => { println!("WARN: Invalid command line arg passed for 'inv_costing_method'. Using default."); "1" }
|
||||
};
|
||||
let clean_inv_costing_arg_string = clean_inv_costing_arg.to_owned();
|
||||
|
||||
let costing_method_choice = cli_user_choices::inv_costing_from_cmd_arg(clean_inv_costing_arg_string)?;
|
||||
let costing_method_choice = cli_user_choices::inv_costing_from_cmd_arg(args.inv_costing_method)?;
|
||||
|
||||
let settings = ImportProcessParameters {
|
||||
export_path: output_dir_path,
|
||||
|
|
|
@ -34,7 +34,7 @@ pub(crate) fn wizard(args: super::Cli) -> Result<(
|
|||
|
||||
let output_dir_path = args.output_dir_path;
|
||||
|
||||
let costing_method_choice = cli_user_choices::choose_inventory_costing_method()?;
|
||||
let costing_method_choice = cli_user_choices::choose_inventory_costing_method(args.inv_costing_method)?;
|
||||
|
||||
let home_currency_choice = args.home_currency.into_string().unwrap().to_uppercase();
|
||||
|
||||
|
|
Loading…
Reference in New Issue