From cabb6c50101334b96179998a7fd82a4fbeb14fc6 Mon Sep 17 00:00:00 2001 From: scoobybejesus Date: Tue, 8 Dec 2020 00:07:10 -0500 Subject: [PATCH] Separated print menu TUI as feature that can be removed for building on Windows. --- Cargo.toml | 11 +++++++++-- README.md | 10 ++++++++-- crptls/src/core_functions.rs | 1 - src/main.rs | 16 ++++++++++++---- src/setup.rs | 7 +++---- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ab28249..c020fc8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,13 @@ authors = ["scoobybejesus "] edition = "2018" description = "Command-line utility for processing cryptocurrency transactions into 'lots' and 'movements'." +[features] +# The default optional package. Many people will want to use this feature, +# but it is optional because Windows doesn't support it. +default = ["print_menu"] + +print_menu = ["tui", "termion"] + [[bin]] name = "cryptools" path = "src/main.rs" @@ -18,8 +25,8 @@ decimal = "2.0.4" chrono = { version = "0.4", features = ["serde"] } structopt = "0.2.10" rustyline = "5.0.0" -tui = "0.5" -termion = "1.5" +tui = { version = "0.5", optional = true } +termion = { version = "1.5", optional = true } dotenv = "0.14.1" [profile.release] diff --git a/README.md b/README.md index 801e129..be0960e 100644 --- a/README.md +++ b/README.md @@ -82,10 +82,15 @@ You'll choose Delimited, and Comma, and then highlight every column and choose T This will build `./target/debug/cryptools` (or `./target/release/cryptools` for a non-debug build). +### Note on Windows + +Windows won't build with the current TUI print menu. To build on Windows, try with `cargo build --no-default-features`. + ## 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`. +Alternatively, run `cargo run`, in which case command-line parameters for `cryptools` may be entered following `--`, +e.g., `cargo run -- -h` or `cargo run -- my_input_file.csv -ai`. Running with no options/arguments will lead the user through a wizard. To skip the wizard, there are three requirements: @@ -105,7 +110,8 @@ or jump directly to the [examples.md](https://github.com/scoobybejesus/cryptools 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. +Alternatively, the respective environment variables may be set manually, +or it may be easier to choose the proper command line flag (such as `-d` for `date_separator_is_slash` or `-i` for `iso_date`.). #### Pro Tip diff --git a/crptls/src/core_functions.rs b/crptls/src/core_functions.rs index 7e5c0cc..9ab987b 100644 --- a/crptls/src/core_functions.rs +++ b/crptls/src/core_functions.rs @@ -31,7 +31,6 @@ pub struct ImportProcessParameters { pub lk_basis_date_preserved: bool, pub should_export: bool, pub export_path: PathBuf, - pub print_menu: bool, pub journal_entry_export: bool, } diff --git a/src/main.rs b/src/main.rs index 93bd930..7b032a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,9 +17,11 @@ mod setup; mod cli_user_choices; mod wizard; mod skip_wizard; -mod mytui; mod export; +#[cfg(feature = "print_menu")] +mod mytui; + use export::{export_all, export_je}; @@ -43,6 +45,7 @@ pub struct Cli { /// Once the file_to_import has been fully processed, the user will be presented /// with a menu for manually selecting which reports to print/export. If this flag is not /// set, the program will print/export all available reports. + #[cfg(feature = "print_menu")] #[structopt(name = "print menu", short, long = "print-menu")] print_menu: bool, @@ -124,7 +127,7 @@ change default program behavior. let cfg = setup::get_env(&args)?; - let (input_file_path, settings) = setup::run_setup(args, cfg)?; + let (input_file_path, settings) = setup::run_setup(&args, cfg)?; let ( raw_acct_map, @@ -134,10 +137,14 @@ change default program behavior. ) = crptls::core_functions::import_and_process_final(input_file_path, &settings)?; let mut should_export_all = settings.should_export; - let present_print_menu_tui = settings.print_menu; - let print_journal_entries_only = settings.journal_entry_export; + #[cfg(feature = "print_menu")] + let present_print_menu_tui: bool = args.print_menu.to_owned(); + + #[cfg(feature = "print_menu")] if present_print_menu_tui { should_export_all = false } + + let print_journal_entries_only = settings.journal_entry_export; if print_journal_entries_only { should_export_all = false } if should_export_all { @@ -162,6 +169,7 @@ change default program behavior. )?; } + #[cfg(feature = "print_menu")] if present_print_menu_tui { mytui::print_menu_tui::print_menu_tui( diff --git a/src/setup.rs b/src/setup.rs index a2f7c10..b4be2b2 100644 --- a/src/setup.rs +++ b/src/setup.rs @@ -110,14 +110,14 @@ pub struct ArgsForImportVarsTBD { pub suppress_reports: bool, } -pub (crate) fn run_setup(cmd_args: super::Cli, cfg: super::Cfg) -> Result<(PathBuf, ImportProcessParameters), Box> { +pub (crate) fn run_setup(cmd_args: &super::Cli, cfg: super::Cfg) -> Result<(PathBuf, ImportProcessParameters), Box> { let date_separator = match cfg.date_separator_is_slash { false => { "-" } // Default true => { "/" } // Overridden by env var or cmd line flag }; - let input_file_path = match cmd_args.file_to_import { + let input_file_path = match cmd_args.file_to_import.to_owned() { Some(file) => { if File::open(&file).is_ok() { file @@ -137,7 +137,7 @@ pub (crate) fn run_setup(cmd_args: super::Cli, cfg: super::Cfg) -> Result<(PathB let wizard_or_not_args = ArgsForImportVarsTBD { inv_costing_method_arg: cfg.inv_costing_method, lk_cutoff_date_arg: cfg.lk_cutoff_date, - output_dir_path: cmd_args.output_dir_path, + output_dir_path: cmd_args.output_dir_path.to_owned(), suppress_reports: cmd_args.suppress_reports, }; @@ -165,7 +165,6 @@ pub (crate) fn run_setup(cmd_args: super::Cli, cfg: super::Cfg) -> Result<(PathB lk_basis_date_preserved: true, // TODO should_export, export_path: output_dir_path, - print_menu: cmd_args.print_menu, journal_entry_export: cmd_args.journal_entries_only, };