Clippy formatting.
This commit is contained in:
parent
7db7daab13
commit
248d45261b
|
@ -93,16 +93,16 @@ fn _get_path() -> Result<(String, bool), Box<dyn Error>> {
|
|||
rl.helper_mut().unwrap().colored_prompt = format!("\x1b[1;32m{}\x1b[0m", p);
|
||||
let readline = rl.readline(">> ");
|
||||
|
||||
fn begins_with_tilde(unchecked_path: &String) -> bool {
|
||||
match unchecked_path.find("~") {
|
||||
Some(0) => return true,
|
||||
_ => return false
|
||||
fn begins_with_tilde(unchecked_path: &str) -> bool {
|
||||
match unchecked_path.find('~') {
|
||||
Some(0) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
match readline {
|
||||
Ok(line) => {
|
||||
println!("");
|
||||
println!();
|
||||
let has_tilde = begins_with_tilde(&line);
|
||||
if has_tilde {
|
||||
println!("Unfortunately, the tilde '~' cannot be used as a shortcut for your home directory.\n");
|
||||
|
@ -167,7 +167,7 @@ pub(crate) fn elect_like_kind_treatment(cutoff_date_arg: &mut Option<String>) ->
|
|||
Some(mut cutoff_date_arg) => {
|
||||
|
||||
let provided_date = NaiveDate::parse_from_str(&cutoff_date_arg, "%y-%m-%d")
|
||||
.unwrap_or(NaiveDate::parse_from_str(&cutoff_date_arg, "%Y-%m-%d")
|
||||
.unwrap_or_else(|_| NaiveDate::parse_from_str(&cutoff_date_arg, "%Y-%m-%d")
|
||||
.unwrap_or_else(|_| {
|
||||
println!("\nWARN: Date entered after -l command line arg (like-kind cutoff date) has an invalid format.");
|
||||
second_date_try_from_user(&mut cutoff_date_arg).unwrap()
|
||||
|
@ -177,7 +177,7 @@ pub(crate) fn elect_like_kind_treatment(cutoff_date_arg: &mut Option<String>) ->
|
|||
|
||||
let (election, date_string) = _elect_like_kind_arg(&cutoff_date_arg, provided_date)?;
|
||||
|
||||
fn _elect_like_kind_arg(cutoff_date_arg: &String, provided_date: NaiveDate) -> Result<(bool, String), Box<dyn Error>> {
|
||||
fn _elect_like_kind_arg(cutoff_date_arg: &str, provided_date: NaiveDate) -> Result<(bool, String), Box<dyn Error>> {
|
||||
|
||||
let mut input = String::new();
|
||||
let stdin = io::stdin();
|
||||
|
@ -267,7 +267,7 @@ pub(crate) fn elect_like_kind_treatment(cutoff_date_arg: &mut Option<String>) ->
|
|||
fn test_naive_date_from_user_string(input: &mut String) -> Result<NaiveDate, Box<dyn Error>> {
|
||||
|
||||
let successfully_parsed_naive_date = NaiveDate::parse_from_str(&input, "%y-%m-%d")
|
||||
.unwrap_or(NaiveDate::parse_from_str(&input, "%Y-%m-%d")
|
||||
.unwrap_or_else(|_| NaiveDate::parse_from_str(&input, "%Y-%m-%d")
|
||||
.unwrap_or_else(|_| { second_date_try_from_user(input).unwrap() } ));
|
||||
|
||||
Ok(successfully_parsed_naive_date)
|
||||
|
@ -284,7 +284,7 @@ pub(crate) fn elect_like_kind_treatment(cutoff_date_arg: &mut Option<String>) ->
|
|||
*input = input2;
|
||||
|
||||
let successfully_parsed_naive_date = NaiveDate::parse_from_str(&input, "%y-%m-%d")
|
||||
.unwrap_or(NaiveDate::parse_from_str(&input, "%Y-%m-%d")
|
||||
.unwrap_or_else(|_| NaiveDate::parse_from_str(&input, "%Y-%m-%d")
|
||||
.unwrap_or_else(|_| { second_date_try_from_user(input).unwrap() } ));
|
||||
|
||||
Ok(successfully_parsed_naive_date)
|
||||
|
|
|
@ -23,8 +23,8 @@ pub struct RawAccount {
|
|||
}
|
||||
|
||||
impl RawAccount {
|
||||
pub fn is_home_currency(&self, compare: &String) -> bool {
|
||||
&self.ticker == compare
|
||||
pub fn is_home_currency(&self, compare: &str) -> bool {
|
||||
self.ticker == compare
|
||||
}
|
||||
|
||||
pub fn margin_string(&self) -> String {
|
||||
|
|
|
@ -101,9 +101,9 @@ pub fn import_and_process_final(
|
|||
transactions_map = create_lots_mvmts::create_lots_and_movements(
|
||||
transactions_map,
|
||||
&action_records_map,
|
||||
&mut raw_account_map,
|
||||
&mut account_map,
|
||||
&settings.home_currency,
|
||||
&raw_account_map,
|
||||
&account_map,
|
||||
&settings.home_currency.as_str(),
|
||||
&settings.costing_method,
|
||||
settings.lk_treatment_enabled,
|
||||
settings.lk_cutoff_date,
|
||||
|
|
|
@ -19,7 +19,7 @@ pub(crate) fn create_lots_and_movements(
|
|||
ar_map: &HashMap<u32, ActionRecord>,
|
||||
raw_acct_map: &HashMap<u16, RawAccount>,
|
||||
acct_map: &HashMap<u16, Account>,
|
||||
chosen_home_currency: &String,
|
||||
chosen_home_currency: &str,
|
||||
chosen_costing_method: &InventoryCostingMethod,
|
||||
enable_lk_treatment: bool,
|
||||
like_kind_cutoff_date: NaiveDate,
|
||||
|
@ -646,7 +646,7 @@ fn wrap_mvmt_and_push(
|
|||
this_mvmt: Movement,
|
||||
ar: &ActionRecord,
|
||||
lot: &Lot,
|
||||
chosen_home_currency: &String,
|
||||
chosen_home_currency: &str,
|
||||
raw_acct_map: &HashMap<u16, RawAccount>,
|
||||
acct_map: &HashMap<u16, Account>,
|
||||
) {
|
||||
|
@ -654,7 +654,7 @@ fn wrap_mvmt_and_push(
|
|||
let acct = acct_map.get(&ar.account_key).unwrap();
|
||||
let raw_acct = raw_acct_map.get(&acct.raw_key).unwrap();
|
||||
|
||||
if ar.direction() == Polarity::Outgoing && !raw_acct.is_home_currency(&chosen_home_currency) {
|
||||
if ar.direction() == Polarity::Outgoing && !raw_acct.is_home_currency(chosen_home_currency) {
|
||||
let ratio = this_mvmt.amount / ar.amount;
|
||||
this_mvmt.ratio_of_amt_to_outgoing_mvmts_in_a_r.set(round_d128_1e8(&ratio));
|
||||
}
|
||||
|
@ -675,7 +675,7 @@ fn fit_into_lots(
|
|||
list_of_lots_to_use: RefCell<Vec<Rc<Lot>>>,
|
||||
vec_of_ordered_index_values: Vec<usize>,
|
||||
index_position: usize,
|
||||
chosen_home_currency: &String,
|
||||
chosen_home_currency: &str,
|
||||
ar_map: &HashMap<u32, ActionRecord>,
|
||||
raw_acct_map: &HashMap<u16, RawAccount>,
|
||||
acct_map: &HashMap<u16, Account>,
|
||||
|
@ -812,7 +812,7 @@ fn process_multiple_incoming_lots_and_mvmts(
|
|||
txn_num: u32,
|
||||
outgoing_ar: &ActionRecord,
|
||||
incoming_ar: &ActionRecord,
|
||||
chosen_home_currency: &String,
|
||||
chosen_home_currency: &str,
|
||||
incoming_ar_key: u32,
|
||||
raw_acct_map: &HashMap<u16, RawAccount>,
|
||||
acct_map: &HashMap<u16, Account>,
|
||||
|
|
|
@ -86,10 +86,10 @@ The next column's value should be 2, then 3, etc, until the final account).";
|
|||
};
|
||||
|
||||
let just_account: RawAccount = RawAccount {
|
||||
account_num: account_num,
|
||||
name: name,
|
||||
ticker: ticker,
|
||||
is_margin: is_margin,
|
||||
account_num,
|
||||
name,
|
||||
ticker,
|
||||
is_margin,
|
||||
};
|
||||
|
||||
raw_acct_map.insert(account_num, just_account);
|
||||
|
@ -166,7 +166,7 @@ pub(crate) fn import_transactions(
|
|||
if amount != amount_rounded { changed_action_records += 1; changed_txn_num.push(this_tx_number); }
|
||||
|
||||
let action_record = ActionRecord {
|
||||
account_key: account_key,
|
||||
account_key,
|
||||
amount: amount_rounded,
|
||||
tx_key: this_tx_number,
|
||||
self_ar_key: this_ar_number,
|
||||
|
@ -185,35 +185,29 @@ pub(crate) fn import_transactions(
|
|||
}
|
||||
}
|
||||
|
||||
match incoming_ar {
|
||||
Some(incoming_ar) => {
|
||||
if let Some(incoming_ar) = incoming_ar {
|
||||
let x = incoming_ar_num.unwrap();
|
||||
action_records.insert(x, incoming_ar);
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
|
||||
match outgoing_ar {
|
||||
Some(outgoing_ar) => {
|
||||
if let Some(outgoing_ar) = outgoing_ar {
|
||||
let y = outgoing_ar_num.unwrap();
|
||||
action_records.insert(y, outgoing_ar);
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
|
||||
let format_yy: String;
|
||||
let format_yyyy: String;
|
||||
|
||||
if iso {
|
||||
format_yyyy = "%Y".to_owned() + sep + &"%d" + sep + "%m";
|
||||
format_yy = "%y".to_owned() + sep + &"%d" + sep + "%m";
|
||||
format_yyyy = "%Y".to_owned() + sep + "%d" + sep + "%m";
|
||||
format_yy = "%y".to_owned() + sep + "%d" + sep + "%m";
|
||||
} else {
|
||||
format_yyyy = "%m".to_owned() + sep + &"%d" + sep + "%Y";
|
||||
format_yy = "%m".to_owned() + sep + &"%d" + sep + "%y";
|
||||
format_yyyy = "%m".to_owned() + sep + "%d" + sep + "%Y";
|
||||
format_yy = "%m".to_owned() + sep + "%d" + sep + "%y";
|
||||
}
|
||||
|
||||
let tx_date = NaiveDate::parse_from_str(this_tx_date, &format_yy)
|
||||
.unwrap_or(NaiveDate::parse_from_str(this_tx_date, &format_yyyy)
|
||||
.unwrap_or_else(|_| NaiveDate::parse_from_str(this_tx_date, &format_yyyy)
|
||||
.expect("
|
||||
Failed to parse date in input file. Check date separator character (which is a hyphen unless modified via Cli option -d).\n")
|
||||
);
|
||||
|
|
|
@ -150,7 +150,7 @@ impl Transaction {
|
|||
|
||||
pub fn get_outgoing_exchange_and_flow_mvmts(
|
||||
&self,
|
||||
user_home_currency: &String,
|
||||
user_home_currency: &str,
|
||||
ars: &HashMap<u32, ActionRecord>,
|
||||
raw_acct_map: &HashMap<u16, RawAccount>,
|
||||
acct_map: &HashMap<u16, Account>,
|
||||
|
@ -194,7 +194,7 @@ impl Transaction {
|
|||
ars: &HashMap<u32, ActionRecord>,
|
||||
raw_acct_map: &HashMap<u16, RawAccount>,
|
||||
acct_map: &HashMap<u16, Account>,
|
||||
home_currency: &String,
|
||||
home_currency: &str,
|
||||
) -> Result<bool, Box<dyn Error>> {
|
||||
|
||||
assert_eq!(self.action_record_idx_vec.len(), (2 as usize));
|
||||
|
@ -218,7 +218,7 @@ impl Transaction {
|
|||
ars: &HashMap<u32, ActionRecord>,
|
||||
raw_accts: &HashMap<u16, RawAccount>,
|
||||
acct_map: &HashMap<u16, Account>,
|
||||
home_currency: &String,
|
||||
home_currency: &str,
|
||||
) -> Result<String, Box<dyn Error>> {
|
||||
|
||||
let auto_memo = if self.action_record_idx_vec.len() == 2 {
|
||||
|
@ -363,9 +363,7 @@ impl ActionRecord {
|
|||
|
||||
for mvmt in lot.movements.borrow().iter() {
|
||||
|
||||
if (mvmt.date) <= txn.date {
|
||||
|
||||
if mvmt.action_record_key == self.self_ar_key {
|
||||
if (mvmt.date) <= txn.date && mvmt.action_record_key == self.self_ar_key {
|
||||
|
||||
measure += mvmt.amount;
|
||||
|
||||
|
@ -375,7 +373,6 @@ impl ActionRecord {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("ERROR: This should never print.");
|
||||
movements_in_ar
|
||||
}
|
||||
|
|
|
@ -440,9 +440,9 @@ pub fn _5_transaction_mvmt_summaries_to_csv(
|
|||
if count == 0 { tx_type_string = mvmt.friendly_tx_type(&tx_type) };
|
||||
count += 1;
|
||||
|
||||
if let None = ticker { ticker = Some(raw_acct.ticker.clone()) };
|
||||
if ticker.is_none() { ticker = Some(raw_acct.ticker.clone()) };
|
||||
|
||||
if let None = polarity {
|
||||
if polarity.is_none() {
|
||||
polarity = if mvmt.amount > d128!(0) {
|
||||
Some(Polarity::Incoming)
|
||||
} else { Some(Polarity::Outgoing)
|
||||
|
@ -455,16 +455,13 @@ pub fn _5_transaction_mvmt_summaries_to_csv(
|
|||
amount_lt += mvmt.amount;
|
||||
proceeds_lt += mvmt.proceeds_lk.get();
|
||||
cost_basis_lt += mvmt.cost_basis_lk.get();
|
||||
match term_lt {
|
||||
None => { term_lt = Some(term)}
|
||||
_ => {}
|
||||
}
|
||||
if term_lt.is_none() { term_lt = Some(term) }
|
||||
} else {
|
||||
assert_eq!(term, Term::ST);
|
||||
amount_st += mvmt.amount;
|
||||
proceeds_st += mvmt.proceeds_lk.get();
|
||||
cost_basis_st += mvmt.cost_basis_lk.get();
|
||||
if term_st == None {
|
||||
if term_st.is_none() {
|
||||
term_st = Some(term);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ depending on the bookkeeping practices you employ.";
|
|||
|
||||
for mvmt in flow_or_outgoing_exchange_movements.iter() {
|
||||
|
||||
if let None = polarity {
|
||||
if polarity.is_none() {
|
||||
polarity = if mvmt.amount > d128!(0) {
|
||||
Some(Polarity::Incoming)
|
||||
} else { Some(Polarity::Outgoing)
|
||||
|
@ -135,16 +135,13 @@ depending on the bookkeeping practices you employ.";
|
|||
amount_lt += mvmt.amount;
|
||||
proceeds_lt += mvmt.proceeds_lk.get();
|
||||
cost_basis_lt += mvmt.cost_basis_lk.get();
|
||||
match term_lt {
|
||||
None => { term_lt = Some(term)}
|
||||
_ => {}
|
||||
}
|
||||
if term_lt.is_none() { term_lt = Some(term) }
|
||||
} else {
|
||||
assert_eq!(term, Term::ST);
|
||||
amount_st += mvmt.amount;
|
||||
proceeds_st += mvmt.proceeds_lk.get();
|
||||
cost_basis_st += mvmt.cost_basis_lk.get();
|
||||
if term_st == None {
|
||||
if term_st.is_none() {
|
||||
term_st = Some(term);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -410,8 +410,7 @@ Enable like-kind treatment: {}",
|
|||
|
||||
let movements_sum = lot.get_sum_of_amts_in_lot();
|
||||
|
||||
if acct.list_of_lots.borrow().len() > 0 {
|
||||
if movements_sum > d128!(0) {
|
||||
if acct.list_of_lots.borrow().len() > 0 && movements_sum > d128!(0) {
|
||||
|
||||
writeln!(file, " Lot {:>3} created {} w/ basis date {} • Σ: {:>12}, and cost basis of {:>10.2}",
|
||||
(lot_idx+1),
|
||||
|
@ -423,7 +422,6 @@ Enable like-kind treatment: {}",
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -150,9 +150,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
)?;
|
||||
}
|
||||
|
||||
if print_journal_entries_only {
|
||||
if print_journal_entries_only && !settings.lk_treatment_enabled {
|
||||
|
||||
if !settings.lk_treatment_enabled {
|
||||
export_je::prepare_non_lk_journal_entries(
|
||||
&settings,
|
||||
&action_records_map,
|
||||
|
@ -161,7 +160,6 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
&transactions_map,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
if present_print_menu_tui {
|
||||
|
||||
|
|
|
@ -48,9 +48,9 @@ pub (crate) fn print_menu_tui(
|
|||
|
||||
ui::draw(&mut terminal, &app)?;
|
||||
|
||||
match events.next()? {
|
||||
if let Event::Input(key) = events.next()? {
|
||||
|
||||
Event::Input(key) => match key {
|
||||
match key {
|
||||
|
||||
Key::Char(c) => {
|
||||
app.on_key(c);
|
||||
|
@ -62,8 +62,7 @@ pub (crate) fn print_menu_tui(
|
|||
app.on_down();
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
if app.should_quit {
|
||||
|
|
16
src/setup.rs
16
src/setup.rs
|
@ -52,15 +52,11 @@ pub (crate) fn run_setup(args: super::Cli) -> Result<(PathBuf, ImportProcessPara
|
|||
output_dir_path,
|
||||
) = wizard_or_not(args.flags.accept_args, wizard_or_not_args)?;
|
||||
|
||||
let like_kind_cutoff_date;
|
||||
|
||||
if like_kind_election {
|
||||
like_kind_cutoff_date = NaiveDate::parse_from_str(&like_kind_cutoff_date_string, "%y-%m-%d")
|
||||
.unwrap_or(NaiveDate::parse_from_str(&like_kind_cutoff_date_string, "%Y-%m-%d")
|
||||
.expect("Command line date (like-kind cutoff option) has an incorrect format. Program must abort."));
|
||||
} else {
|
||||
like_kind_cutoff_date = NaiveDate::parse_from_str(&"1-1-1", "%y-%m-%d").unwrap();
|
||||
}
|
||||
let like_kind_cutoff_date = if like_kind_election {
|
||||
NaiveDate::parse_from_str(&like_kind_cutoff_date_string, "%y-%m-%d")
|
||||
.unwrap_or_else(|_| NaiveDate::parse_from_str(&like_kind_cutoff_date_string, "%Y-%m-%d")
|
||||
.expect("Command line date (like-kind cutoff option) has an incorrect format. Program must abort."))
|
||||
} else { NaiveDate::parse_from_str(&"1-1-1", "%y-%m-%d").unwrap() };
|
||||
|
||||
let settings = ImportProcessParameters {
|
||||
home_currency: args.opts.home_currency.into_string().unwrap().to_uppercase(),
|
||||
|
@ -70,7 +66,7 @@ pub (crate) fn run_setup(args: super::Cli) -> Result<(PathBuf, ImportProcessPara
|
|||
lk_treatment_enabled: like_kind_election,
|
||||
lk_cutoff_date: like_kind_cutoff_date,
|
||||
lk_basis_date_preserved: true, // TODO
|
||||
should_export: should_export,
|
||||
should_export,
|
||||
export_path: output_dir_path,
|
||||
print_menu: args.flags.print_menu,
|
||||
journal_entry_export: args.flags.journal_entries_only,
|
||||
|
|
Loading…
Reference in New Issue