Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Add version fn to print release version to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
ebcrowder committed Aug 27, 2020
1 parent 806fbe3 commit cc1bccb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 3 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod account;
mod balance;
mod csv;
mod register;
mod version;

use crate::error::{Error, Result};
use crate::model::ledger::Group;
Expand All @@ -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<String> = vec![];
let expected_option_args: Vec<String> = vec![
Expand Down Expand Up @@ -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."),
},
}
Expand Down
13 changes: 13 additions & 0 deletions src/cli/version.rs
Original file line number Diff line number Diff line change
@@ -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(())
}

0 comments on commit cc1bccb

Please sign in to comment.