Compare commits
No commits in common. "f117b155cfa2dde8dca9979286c0ef79836f963d" and "90c55062bf0e9309d2f17afd5489da829049335e" have entirely different histories.
f117b155cf
...
90c55062bf
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "cryptools"
|
||||
version = "0.9.1"
|
||||
version = "0.9.0"
|
||||
authors = ["scoobybejesus <scoobybejesus@users.noreply.github.com>"]
|
||||
edition = "2018"
|
||||
description = "Command-line utility for processing cryptocurrency transactions into 'lots' and 'movements'."
|
||||
|
|
|
@ -61,11 +61,11 @@ The rules for successfully preparing and maintaining the input file can generall
|
|||
|
||||
1. The first account must be given number `1`, and each additional account must count up sequentially.
|
||||
2. Margin quote account `ticker`s must be followed by an underscore and the base account ticker (i.e., `BTC_xmr`).
|
||||
3. `Proceeds` is the value of the transaction (measured in the home currency), whether spent, received, or exchanged.
|
||||
3. `Proceeds` is the value of the transaction, whether spent, received, or exchanged.
|
||||
It is **required** in order to properly calculate income/expense/gain/loss.
|
||||
4. `Proceeds` must have a period as a decimal separator (`1,000.00` not `1.000,00`) and must not contain the ticker or symbol (USD or $).
|
||||
5. Only home currency accounts can have negative balances. Crypto accounts may not go negative at any time.
|
||||
(Exception: crypto margin accounts may go negative.)
|
||||
(Exception: crypto margin accounts may go negative, of course.)
|
||||
|
||||
As you can see, most of the rules can generally be ignored.
|
||||
In fact, the only tricky field is the `proceeds` column, but even that becomes second nature soon enough.
|
||||
|
@ -82,18 +82,18 @@ In order to be successfully imported, the CSV input file **must** be in a prescr
|
|||
| | | |Bank |Exchange|Wallet |Exchange|Simplewallet|
|
||||
| | | | USD | BTC | BTC | XMR | XMR |
|
||||
| | | | non | non | non | non | non |
|
||||
|2-1-16 |0 |Bought | -220| 0.25| | | |
|
||||
|3-1-16 |250 |Traded | | -0.25| | 180| |
|
||||
|4-1-16 |0 |Transferred | | | | -90| 90|
|
||||
|5-1-16 |0 |Transferred | | | | 90| -90|
|
||||
|5-2-16 |160 |Traded | | 0.3| | -90| |
|
||||
|6-1-16 |0 |Transferred | | -0.3| 0.3| | |
|
||||
|7-1-16 |200 |Traded | | 0.7| | -90| |
|
||||
|8-1-16 |0 |Transferred | | 0.3| -0.3| | |
|
||||
|9-1-16 |400 |Traded | | -0.5| | 200| |
|
||||
|10-1-16|900 |Traded | | 1| | -200| |
|
||||
|11-1-16|0 |Transferred | | -1.5| 1.5| | |
|
||||
|12-1-16|2000 |Traded* | | | -1.5| | 400|
|
||||
|2/1/16 |0 |Bought | -220| 0.25| | | |
|
||||
|3/1/16 |250 |Traded | | -0.25| | 180| |
|
||||
|4/1/16 |0 |Transferred | | | | -90| 90|
|
||||
|5/1/16 |0 |Transferred | | | | 90| -90|
|
||||
|5/2/16 |160 |Traded | | 0.3| | -90| |
|
||||
|6/1/16 |0 |Transferred | | -0.3| 0.3| | |
|
||||
|7/1/16 |200 |Traded | | 0.7| | -90| |
|
||||
|8/1/16 |0 |Transferred | | 0.3| -0.3| | |
|
||||
|9/1/16 |400 |Traded | | -0.5| | 200| |
|
||||
|10/1/16|900 |Traded | | 1| | -200| |
|
||||
|11/1/16|0 |Transferred | | -1.5| 1.5| | |
|
||||
|12/1/16|2000 |Traded* | | | -1.5| | 400|
|
||||
|
||||
---
|
||||
|
||||
|
@ -187,9 +187,9 @@ Until "spot" funds are spent to pay off the margin loans, it's simply an [unreco
|
|||
##### Columns
|
||||
|
||||
* **txDate**: As a default, this parser expects a format of `MM-dd-YY` or `MM-dd-YYYY`.
|
||||
The ISO 8601 date format (`YYYY-MM-dd` or `YY-MM-dd` both work) may be indicated by setting the environment variable `ISO_DATE` to `1` or `true`.
|
||||
The ISO 8601 date format (`YYYY-MM-dd` or `YY-MM-dd` both work) may be indicated by passing the `-i` flag.
|
||||
The hyphen, slash, or period delimiters (`-`, `/`, or `.`) may be indicated
|
||||
by setting `DATE_SEPARATOR` to `h`, `s`, or `p`, respectively (hyphen, `-`, is default).
|
||||
by passing the `-d` option followed by `h`, `s`, or `p`, respectively (hyphen, `-`, is default).
|
||||
|
||||
* **proceeds**: This is can be any **positive** number that will parse into a floating point 32-bit number,
|
||||
as long as the **decimal separator** is a **period**.
|
||||
|
@ -201,7 +201,7 @@ but be sure not to include the ticker or symbol of the currency
|
|||
* **memo**: This can be a string of characters of any length, though fewer than 20-30 characters is advised.
|
||||
Currently, **commas** in the memo field are **not** supported.
|
||||
|
||||
* *quantity*: This is similar to **proceeds**, in that the **decimal separator** must be a **period**,
|
||||
* *value*: This is similar to **proceeds**, in that the **decimal separator** must be a **period**,
|
||||
and you *cannot* include the ticker or symbol of the currency in that field.
|
||||
It is different from **proceeds** in that this will be parsed into a 128-bit precision decimal floating point number,
|
||||
and a negative value can be indicated via a preceding `-`.
|
||||
|
@ -226,5 +226,5 @@ Anything aside from those six choices will fail to parse.
|
|||
|
||||
* *Transactions*: After the four header rows describing the accounts, the transaction rows follow.
|
||||
Each row is a separate transaction.
|
||||
For each transaction, input the **date**, **proceeds**, **memo**, and **quantity** by which the account balances change.
|
||||
As mentioned elsewhere, a minimum of one and a maximum of two **Accounts** can be associated with a single transaction.
|
||||
For each transaction, input the **date**, **proceeds**, **memo**, and **values** by which the account balances change.
|
||||
As mentioned elsewhere, a minimum of one and a maximum of two Accounts can be associated with a single transaction.
|
27
README.md
27
README.md
|
@ -4,8 +4,8 @@
|
|||
|
||||
###### (The package produces a binary and accompanying library)
|
||||
|
||||
This is a command-line tool that calculates income, expenses, realized gains, realized losses,
|
||||
and holding period from cryptocurrency activity and denominates the results in the user's home currency.
|
||||
This is a command-line tool that calculates income, expenses, realized gains, and realized losses
|
||||
(and holding period) from cryptocurrency activity and denominates the results in the user's home currency.
|
||||
The default home currency is USD, but any currency can be substituted.
|
||||
This tool is probably most useful for filling out a tax return or making tax planning decisions.
|
||||
|
||||
|
@ -29,7 +29,7 @@ containing the user's entire cryptocurrency transaction history, the software wi
|
|||
|
||||
* Two methods each of LIFO or FIFO (compatible w/ the concept of "specific identification")
|
||||
|
||||
* Ability to perform like-kind exchange treatment through a particular date
|
||||
* Ability to perform like-kind exchange treatment
|
||||
|
||||
* Compatible with any (single) home currency
|
||||
|
||||
|
@ -63,27 +63,16 @@ This will build `./target/debug/cryptools` (or `./target/release/cryptools` for
|
|||
## Usage
|
||||
|
||||
Run `./target/debug/cryptools` with no arguments (or with `--help`, or `-h`) to see usage.
|
||||
Alternatively, run `cargo run`, in which case command-line options for `cryptools` may be entered following `--`, e.g., `cargo run -- -h`.
|
||||
|
||||
Running with no options/arguments will lead the user through a wizard.
|
||||
To skip the wizard, there are three requirements:
|
||||
* The [CSV input file](https://github.com/scoobybejesus/cryptools/blob/master/InputFile_CSV.md) is a required command line argument.
|
||||
* The `-a` flag must be passed.
|
||||
* The configuration settings you require are the same as default, or you set the appropriate environment variables, or you have a `.env` file.
|
||||
Alternatively, run `cargo run`, in which case command-line arguments for `cryptools` may be entered following `--`, e.g., `cargo run -- -h`.
|
||||
|
||||
Running with no arguments will lead the user through a wizard; or all required arguments can be passed as command-line flags/options/args.
|
||||
See `/examples/` directory for further guidance,
|
||||
or jump directly to the [examples.md](https://github.com/scoobybejesus/cryptools/blob/master/examples/examples.md) file.
|
||||
|
||||
###### Note: The import of your [CSV input file](https://github.com/scoobybejesus/cryptools/blob/master/InputFile_CSV.md) may fail or behave undesirably with the default configuration settings.
|
||||
See [.env.example](https://github.com/scoobybejesus/cryptools/blob/master/examples/.env.example) for those defaults.
|
||||
If you wish to skip the wizard but require changes to default settings, copy `.env.example` to `.env` and make your changes.
|
||||
The `.env` file must be placed in the directory from which `cryptools` is run or a parent directory.
|
||||
Alternatively, the respective environment variables may be set manually.
|
||||
|
||||
## Development state
|
||||
|
||||
As of fall 2020, the code does not require additional features in order for it to serve the project's founder.
|
||||
At the same time, there are still bells and whistles, creature comforts, etc. that are desired and may be added.
|
||||
As of summer 2019, the code does not require additional features in order for it to serve the project's founder.
|
||||
At the same time, there are plenty of bells and whistles, creature comforts, etc. that are desired and may be added.
|
||||
Additionally, the code could use factoring or general re-working in several areas.
|
||||
|
||||
The software has been tested on Mac, Linux, and FreeBSD.
|
||||
|
@ -112,7 +101,7 @@ My first real progress was with Python, but I still didn't manage to fully devel
|
|||
Luckily, I managed to stumble across a mentor who helped me write 80% of an MVP in strongly-typed Swift.
|
||||
We coded our way into a corner, but I had learned enough to take the code apart and put it back together correctly and complete it.
|
||||
I really enjoyed Swift, but I wanted something even more performant (and cross-platform), and Rust seemed to fit the bill.
|
||||
I rewrote the code in Rust (also with a bit of help), and it has turned out to be a great choice.
|
||||
I rewrote the code in Rust (also with a bit of help from my mentor), and it has turned out to be a great choice.
|
||||
|
||||
## Legal
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ The sample input files and the resulting reports are in the `/examples/resources
|
|||
|
||||
(Note: new reports have been added since the write-up below was written.
|
||||
Nevertheless, evaluating the reports should mostly be self-explanatory.
|
||||
Pass a -p flag from the command line to be presented a full list of available
|
||||
reports to select from once the import has taken place.)
|
||||
Pass a -p flag from the command line to see the full list of available
|
||||
reports - and select from them - once the import has taken place.)
|
||||
|
||||
## 1. Using the wizard
|
||||
|
||||
|
@ -16,14 +16,14 @@ reports to select from once the import has taken place.)
|
|||
##### We're going to pass in that file as a command-line argument (no flags are required).
|
||||
Enter the following:
|
||||
|
||||
##### `cargo run -- examples/resources/faker1__sample_input.csv`
|
||||
##### `cargo run -- ./examples/resources/faker1__sample_input.csv`
|
||||
|
||||
(Substitute a Windows-style file path, if necessary.)
|
||||
|
||||
Running the command above takes you through the wizard.
|
||||
|
||||
(Note: You can simply run **`cargo run`** instead,
|
||||
in which case after answering 'yes' to "Shall we proceed," you will have to enter the path of the input file.)
|
||||
in which case after answering yes to "Shall we proceed," you will have to enter the path of the input file.)
|
||||
|
||||
##### Type `<Enter>` to accept default responses to the first three prompts, which are:
|
||||
|
||||
|
@ -33,51 +33,44 @@ in which case after answering 'yes' to "Shall we proceed," you will have to ente
|
|||
|
||||
##### The final question asks if and where you'd like to save the reports.
|
||||
|
||||
The default is the current directory, which may be undesirable.
|
||||
The default is the current directory, which is probably undesirable.
|
||||
Type `c` and `<Enter>` to change the directory.
|
||||
Then tab-complete your way through `/Users/<your-username>/Documents`, for example, and then `<Enter>`.
|
||||
Then tab-complete your way through `/Users/<your-username>/Documents`*, for example, and then `<Enter>`.
|
||||
|
||||
\* This would be different for Windows, of course.
|
||||
|
||||
##### Now the program has ended, and you should have reports in the directory you provided.
|
||||
|
||||
The reports should generally match those in the `examples/resources` directory,
|
||||
but additional (newer) reports will be generated too.
|
||||
The reports should generally match those in the `examples/resources` directory.
|
||||
(Additional reports are created too, but you can generally match the existing reports by title.)
|
||||
|
||||
|
||||
## 2. Skipping the wizard
|
||||
|
||||
Enter the following:
|
||||
Let's run the program again.
|
||||
This time around, we'll pass command-line parameters to skip the wizard.
|
||||
|
||||
##### `cargo run -- -a examples/resources/faker1__sample_input.csv`
|
||||
##### Again, preview the input file `faker2__sample_input.csv`.
|
||||
|
||||
(Substitute a Windows-style file path, if necessary.)
|
||||
|
||||
This will have quickly and automatically exported all the reports into the current directory.
|
||||
Go delete them before you forget (or feel free to take a look at them first).
|
||||
|
||||
## 3. Using an input file with a slash (`/`) as the date separator
|
||||
|
||||
##### Preview the input file `faker2__sample_input.csv`.
|
||||
|
||||
You'll see it's similar to the first example, though with a wider variety of transactions,
|
||||
You'll see it's similar to the README example, except that there is a wider variety of transactions,
|
||||
plus the memos are more descriptive.
|
||||
More importantly, the date column uses a different format `/` instead of `-`.
|
||||
|
||||
Run:
|
||||
##### Run **`cargo run -- --help`** to see descriptions for the parameters we can use, or just enter:
|
||||
|
||||
##### `DATE_SEPARATOR=s cargo run -- -a -o ~/Documents ./examples/resources/faker2__sample_input.csv`
|
||||
##### `cargo run -- -ds -a -o ~/Documents ./examples/resources/faker2__sample_input.csv`
|
||||
|
||||
\* Substitute `~/Documents` with your desired output directory.
|
||||
Substitute a Windows-style file path, if necessary.
|
||||
|
||||
It worked correctly, right?
|
||||
Note that we set an enviroment variable so the program knew how to parse the date column correctly.
|
||||
An easier way to do this would be to create a `.env` file and set it there.
|
||||
This is described in the README (though there isn't much to it).
|
||||
##### Again, the program runs, and you should have reports in the location you provided.
|
||||
|
||||
###### Try once more. This time, after `-a`, type `-p`, to be presented a "print menu" for choosing individual reports.
|
||||
|
||||
## To recap:
|
||||
We were able to bypass the wizard because:
|
||||
|
||||
1. The required parameters were passed in.
|
||||
2. Default values were used for parameters not passed in.
|
||||
3. The `-a` flag was set which accepts all parameters without asking twice (i.e., skips the wizard).
|
||||
|
||||
The only "required" parameter is the input file.
|
||||
All other parameters have default values.
|
||||
|
@ -85,8 +78,8 @@ The default values may not be desirable for your use case, however.
|
|||
For example, you may want FIFO instead of LIFO,
|
||||
or you may set your home currency to EUR instead of USD.
|
||||
Or maybe you may want to apply like-kind exchange treatment through a particular date.
|
||||
These parameters can all be set via environment variables (or in a `.env` file).
|
||||
See the `--help` screen for command line options and .env.example for information on environment variables.
|
||||
These parameters can all be set via command line options.
|
||||
See the `--help` screen for all the options.
|
||||
|
||||
As mentioned above, pass the -p flag to be presented with a list of available reports.
|
||||
|
||||
|
|
|
@ -2,15 +2,15 @@ txDate,proceeds,memo,1,2,3,4,5
|
|||
,,,Bank,Exchange,Wallet,Exchange,Simplewallet
|
||||
,,,USD,BTC,BTC,XMR,XMR
|
||||
,,,non,non,non,non,non
|
||||
2-1-16,0,FIRST,-220,0.25,,,
|
||||
3-1-16,250,SECOND,,-0.25,,180,
|
||||
4-1-16,0,THIRD,,,,-90,90
|
||||
5-1-16,0,FOURTH,,,,90,-90
|
||||
5-2-16,160,FIFTH,,0.3,,-90,
|
||||
6-1-16,0,SIXTH,,-0.3,0.3,,
|
||||
7-1-16,200,SEVENTH,,0.7,,-90,
|
||||
8-1-16,0,EIGHTH,,0.3,-0.3,,
|
||||
9-1-16,400,NINTH,,-0.5,,200,
|
||||
10-1-16,900,TENTH,,1,,-200,
|
||||
11-1-16,0,ELEVENTH,,-1.5,1.5,,
|
||||
12-1-16,2000,TWELFTH,,,-1.5,,400
|
||||
2/1/16,0,FIRST,-220,0.25,,,
|
||||
3/1/16,250,SECOND,,-0.25,,180,
|
||||
4/1/16,0,THIRD,,,,-90,90
|
||||
5/1/16,0,FOURTH,,,,90,-90
|
||||
5/2/16,160,FIFTH,,0.3,,-90,
|
||||
6/1/16,0,SIXTH,,-0.3,0.3,,
|
||||
7/1/16,200,SEVENTH,,0.7,,-90,
|
||||
8/1/16,0,EIGHTH,,0.3,-0.3,,
|
||||
9/1/16,400,NINTH,,-0.5,,200,
|
||||
10/1/16,900,TENTH,,1,,-200,
|
||||
11/1/16,0,ELEVENTH,,-1.5,1.5,,
|
||||
12/1/16,2000,TWELFTH,,,-1.5,,400
|
|
|
@ -16,7 +16,7 @@ use crate::crptls_lib::create_lots_mvmts;
|
|||
use crate::crptls_lib::costing_method::InventoryCostingMethod;
|
||||
|
||||
|
||||
/// `ImportProcessParameters` are determined from command-line args, environment variables, and/or wizard input from the user.
|
||||
/// `ImportProcessParameters` are determined from command-line args and/or wizard input from the user.
|
||||
/// They are the settings that allow the software to carry out the importing-from-csv of
|
||||
/// `Account`s and `Transaction`s, creation of `Lot`s and `Movement`s, addition of cost basis and proceeds
|
||||
/// to `Movement`s, and application of like-kind treatment, in a specific and automated fashion.
|
||||
|
@ -26,7 +26,7 @@ pub struct ImportProcessParameters {
|
|||
pub home_currency: String,
|
||||
pub costing_method: InventoryCostingMethod,
|
||||
pub lk_treatment_enabled: bool,
|
||||
/// NaiveDate either from "1-1-1" (default and not to be used) or the actual date chosen (or passed in via env var)
|
||||
/// NaiveDate either from "1-1-1" (default and not to be used) or the actual date chosen (or passed in via Cli option)
|
||||
pub lk_cutoff_date: NaiveDate,
|
||||
pub lk_basis_date_preserved: bool,
|
||||
pub should_export: bool,
|
||||
|
@ -60,8 +60,7 @@ pub fn import_and_process_final(
|
|||
&mut transactions_map,
|
||||
)?;
|
||||
|
||||
println!(" Successfully imported csv file.");
|
||||
println!("Processing the data...");
|
||||
println!("Successfully imported csv file.");
|
||||
|
||||
transactions_map = create_lots_mvmts::create_lots_and_movements(
|
||||
&settings,
|
||||
|
@ -72,7 +71,7 @@ pub fn import_and_process_final(
|
|||
// &mut lot_map,
|
||||
)?;
|
||||
|
||||
println!(" Created lots and movements.");
|
||||
println!(" Successfully created lots and movements.");
|
||||
|
||||
import_cost_proceeds_etc::add_cost_basis_to_movements(
|
||||
&settings,
|
||||
|
@ -82,7 +81,7 @@ pub fn import_and_process_final(
|
|||
&transactions_map
|
||||
)?;
|
||||
|
||||
println!(" Added cost basis to movements.");
|
||||
println!(" Successfully added cost basis to movements.");
|
||||
|
||||
import_cost_proceeds_etc::add_proceeds_to_movements(
|
||||
&raw_account_map,
|
||||
|
@ -91,7 +90,8 @@ pub fn import_and_process_final(
|
|||
&transactions_map
|
||||
)?;
|
||||
|
||||
println!(" Added proceeds to movements.");
|
||||
println!(" Successfully added proceeds to movements.");
|
||||
|
||||
|
||||
if settings.lk_treatment_enabled {
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ pub(crate) fn import_from_csv(
|
|||
transactions_map: &mut HashMap<u32, Transaction>,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let file = File::open(import_file_path)?; println!("\nCSV ledger file opened successfully.\n");
|
||||
let file = File::open(import_file_path)?; println!("CSV ledger file opened successfully.\n");
|
||||
|
||||
let mut rdr = csv::ReaderBuilder::new()
|
||||
.has_headers(true)
|
||||
|
@ -240,8 +240,7 @@ fn import_transactions(
|
|||
let tx_date = NaiveDate::parse_from_str(this_tx_date, &format_yy)
|
||||
.unwrap_or_else(|_| NaiveDate::parse_from_str(this_tx_date, &format_yyyy)
|
||||
.expect("
|
||||
Failed to parse date in input file. Check date the separator character, which is expected to be a hyphen \
|
||||
unless otherwise set via environment variable or .env file. See `.env.example.`\n")
|
||||
Failed to parse date in input file. Check date separator character (which is a hyphen unless modified via Cli option -d).\n")
|
||||
);
|
||||
|
||||
let transaction = Transaction {
|
||||
|
|
28
src/main.rs
28
src/main.rs
|
@ -95,22 +95,22 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
let args = Cli::from_args();
|
||||
|
||||
println!(
|
||||
"\
|
||||
Hello!
|
||||
|
||||
This software will import your csv file's ledger of cryptocurrency transactions.
|
||||
It will then process it by creating 'lots' and posting 'movements' to those lots.
|
||||
Along the way, it will keep track of income, expenses, gains, and losses.
|
||||
|
||||
See .env.example for environment variables that may be set in a .env file in order to
|
||||
change default program behavior.
|
||||
|
||||
Note: The software is designed to import a full history. Gains and losses may be incorrect otherwise.
|
||||
");
|
||||
|
||||
let cfg = setup::get_env()?;
|
||||
|
||||
println!(
|
||||
"
|
||||
Hello,
|
||||
|
||||
This software will import your csv file's ledger of cryptocurrency transactions.
|
||||
It will then process it by creating 'lots' and posting 'movements' to those lots.
|
||||
Along the way, it will keep track of income, expenses, gains, and losses.
|
||||
|
||||
See .env.example for environment variables that may be set in a .env file in order to
|
||||
change default program behavior.
|
||||
|
||||
Note: The software is designed to import a full history. Gains and losses may be incorrect otherwise.
|
||||
");
|
||||
|
||||
let (input_file_path, settings) = setup::run_setup(args, cfg)?;
|
||||
|
||||
let (
|
||||
|
|
40
src/setup.rs
40
src/setup.rs
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) 2017-2019, scoobybejesus
|
||||
// Redistributions must include the license: https://github.com/scoobybejesus/cryptools/blob/master/LEGAL.txt
|
||||
|
||||
// use std::ffi::OsString;
|
||||
use std::path::PathBuf;
|
||||
use std::error::Error;
|
||||
use std::process;
|
||||
|
@ -19,14 +20,13 @@ use crate::wizard;
|
|||
|
||||
pub fn get_env() -> Result<super::Cfg, Box<dyn Error>> {
|
||||
|
||||
match dotenv::dotenv() {
|
||||
Ok(_path) => {println!("Setting environment variables from .env file.")},
|
||||
Err(_e) => println!("Did not find .env file.")
|
||||
}
|
||||
dotenv::dotenv().expect("Failed to read .env file");
|
||||
|
||||
let iso_date: bool = match env::var("ISO_DATE") {
|
||||
Ok(val) => {
|
||||
if val == "1" || val.to_lowercase() == "true" {
|
||||
let var_lower = val.to_lowercase();
|
||||
let val_str = var_lower.as_str();
|
||||
if val_str == "1" || val == "true" {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
@ -36,37 +36,23 @@ pub fn get_env() -> Result<super::Cfg, Box<dyn Error>> {
|
|||
};
|
||||
|
||||
let date_separator: String = match env::var("DATE_SEPARATOR") {
|
||||
Ok(val) => {
|
||||
println!(" Found DATE_SEPARATOR env var: {}", val);
|
||||
val.to_lowercase()},
|
||||
Err(_e) => {
|
||||
println!(" Using default date separator (hyphen).");
|
||||
"h".to_string()},
|
||||
Ok(val) => val.to_lowercase(),
|
||||
Err(_e) => "h".to_string(),
|
||||
};
|
||||
|
||||
let home_currency = match env::var("HOME_CURRENCY") {
|
||||
Ok(val) => {
|
||||
println!(" Found HOME_CURRENCY env var: {}", val);
|
||||
val.to_uppercase()},
|
||||
Err(_e) => {
|
||||
println!(" Using default home currency (USD).");
|
||||
"USD".to_string()},
|
||||
Ok(val) => val.to_uppercase(),
|
||||
Err(_e) => "USD".to_string(),
|
||||
};
|
||||
|
||||
let lk_cutoff_date = match env::var("LK_CUTOFF_DATE") {
|
||||
Ok(val) => {
|
||||
println!(" Found LK_CUTOFF_DATE env var: {}", val);
|
||||
Some(val)},
|
||||
Ok(val) => Some(val),
|
||||
Err(_e) => None,
|
||||
};
|
||||
|
||||
let inv_costing_method = match env::var("INV_COSTING_METHOD") {
|
||||
Ok(val) => {
|
||||
println!(" Found INV_COSTING_METHOD env var: {}", val);
|
||||
val},
|
||||
Err(_e) => {
|
||||
println!(" Using default inventory costing method (LIFO by lot creation date).");
|
||||
"1".to_string()},
|
||||
Ok(val) => val,
|
||||
Err(_e) => "1".to_string(),
|
||||
};
|
||||
|
||||
let cfg = super::Cfg {
|
||||
|
@ -120,7 +106,7 @@ pub (crate) fn run_setup(cmd_args: super::Cli, cfg: super::Cfg) -> Result<(PathB
|
|||
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("Environment variable for LK_CUTOFF_DATE has an incorrect format. Program must abort. See .env.example."))
|
||||
.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 {
|
||||
|
|
Loading…
Reference in New Issue