From 91ad76b955fad52934e3ea775f9ff61d18c30a8d Mon Sep 17 00:00:00 2001 From: Julian Dax Date: Fri, 30 Sep 2022 18:30:46 +0200 Subject: [PATCH] feat: add --version --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 13 +++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b0e7a27..b280457 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,7 +16,7 @@ checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" [[package]] name = "json_env" -version = "1.0.7" +version = "1.1.0" dependencies = [ "anyhow", "serde", diff --git a/Cargo.toml b/Cargo.toml index 20214b7..86ee39e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "json_env" -version = "1.0.7" +version = "1.1.0" edition = "2021" license = "Apache-2.0" description ="`json_env` loads an environment variables from a file called `.env.json` in the current directory and starts a subprocess with them." diff --git a/src/main.rs b/src/main.rs index ec89622..c1810d8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,9 @@ use std::fs::File; use std::io::Read; use std::process::Command; + +const VERSION: &str = env!("CARGO_PKG_VERSION"); + // `json_env` is [dotenv](https://github.com/motdotla/dotenv), but with JSON. // See [readme](Readme.md) for more information. fn main() { @@ -12,7 +15,7 @@ fn main() { let help_text = concat!("json_env reads the .env.json file in the current directory and runs a program with these environment variables.\n", "Usage:", "json_env \n", - "json_env itself has no config options" + "json_env itself has no config options." ); if args.len() < 2 { @@ -20,7 +23,13 @@ fn main() { } if args[1] == "--help" { - println!("{}", help_text) + println!("{}", help_text); + return; + } + + if args[1] == "--version" { + println!("json_env version {}", VERSION); + return; } match File::open(".env.json") {