From cc1bccb5883f539bc2a4c93cc4ae6aeebee0a74d Mon Sep 17 00:00:00 2001 From: ebcrowder Date: Tue, 25 Aug 2020 20:33:59 -0700 Subject: [PATCH] Add version fn to print release version to stdout --- README.md | 3 +++ src/cli.rs | 3 +++ src/cli/version.rs | 13 +++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 src/cli/version.rs diff --git a/README.md b/README.md index 38ac710..c3501dd 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,9 @@ Date Description Accounts - **note** - prior to importing your `csv` file into the tool, you must rename the columns in the first line of the `csv` file in the following schema: `"date","transaction","name","memo","amount"`. +- version + - prints release version to `stdout`. + ### rust_ledger `yaml` file format - example ledger `yaml` file can be found at `examples/example.yaml` diff --git a/src/cli.rs b/src/cli.rs index c652fc0..976006b 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -2,6 +2,7 @@ mod account; mod balance; mod csv; mod register; +mod version; use crate::error::{Error, Result}; use crate::model::ledger::Group; @@ -17,6 +18,7 @@ pub fn run() -> Result<()> { String::from("balance"), String::from("register"), String::from("csv"), + String::from("version"), ]; let expected_flag_args: Vec = vec![]; let expected_option_args: Vec = vec![ @@ -73,6 +75,7 @@ pub fn run() -> Result<()> { "balance" => balance::balance(ledger_file), "register" => register::register(ledger_file, &options_arg, group_arg), "csv" => csv::csv(ledger_file, &options_arg, &offset_arg), + "version" => version::version(), _ => panic!("command not found."), }, } diff --git a/src/cli/version.rs b/src/cli/version.rs new file mode 100644 index 0000000..ceaad58 --- /dev/null +++ b/src/cli/version.rs @@ -0,0 +1,13 @@ +use crate::error::Result; + +/// returns package version +pub fn version() -> Result<()> { + let cargo_pkg_version = option_env!("CARGO_PKG_VERSION"); + + match cargo_pkg_version { + Some(v) => println!("rust_ledger {:?}", v), + None => println!("version not found in Cargo.toml"), + } + + Ok(()) +}