diff options
author | Galen Guyer <galen@galenguyer.com> | 2022-07-12 23:32:37 -0400 |
---|---|---|
committer | Galen Guyer <galen@galenguyer.com> | 2022-07-12 23:32:37 -0400 |
commit | 29d50f48e12e459693528330ddb5c33273bab140 (patch) | |
tree | 982c5e87759b101e69aafec1b79497816bd8bf90 | |
parent | afc6bf5bf802f470c427424f440f51a7dc2ec5a5 (diff) |
load default env from ~/.hancock, add license
-rw-r--r-- | Cargo.lock | 33 | ||||
-rw-r--r-- | Cargo.toml | 9 | ||||
-rw-r--r-- | LICENSE | 8 | ||||
-rw-r--r-- | src/cli.rs | 18 |
4 files changed, 63 insertions, 5 deletions
@@ -69,6 +69,15 @@ dependencies = [ ] [[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + +[[package]] name = "dirs-next" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -79,6 +88,17 @@ dependencies = [ ] [[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] name = "dirs-sys-next" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -90,6 +110,15 @@ dependencies = [ ] [[package]] +name = "dotenvy" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e851a83c30366fd01d75b913588e95e74a1705c1ecc5d58b1f8e1a6d556525f" +dependencies = [ + "dirs", +] + +[[package]] name = "foreign-types" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -117,9 +146,11 @@ dependencies = [ [[package]] name = "hancock" -version = "1.2.0" +version = "1.3.0" dependencies = [ "clap", + "dirs", + "dotenvy", "openssl", "path-absolutize", "shellexpand", @@ -1,8 +1,9 @@ [package] name = "hancock" -version = "1.2.0" +authors = ["Galen Guyer <galen@galenguyer.com>"] +version = "1.3.0" edition = "2021" - +license = "MIT" [lib] path = "src/lib/mod.rs" @@ -15,8 +16,8 @@ path = "src/cli.rs" [dependencies] clap = { version = "3.1.6", features = ["cargo", "derive", "env", "wrap_help"] } +dirs = "4.0.0" +dotenvy = "0.15.1" openssl = "0.10.38" path-absolutize = "3.0.12" shellexpand = "2.1.0" - -[features] @@ -0,0 +1,8 @@ +Copyright © 2022 Galen Guyer <galen@galenguyer.com> + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + @@ -1,3 +1,4 @@ +use std::path::Path; use clap::{Parser, Subcommand}; use hancock::ops::*; @@ -18,6 +19,23 @@ pub enum Commands { } fn main() { + let env_file = match Path::new(".env").exists() { + true => Some(String::from(".env")), + false => { + match Path::new(&dirs::home_dir().unwrap()).join(".hancock").exists() { + true => Some(Path::new(&dirs::home_dir().unwrap()).join(".hancock").to_str().unwrap().to_owned()), + false => None + } + } + }; + + if let Some(file) = env_file { + dotenvy::from_path(Path::new(&file)).ok(); + } + + #[cfg(not(debug_assertions))] + let cli = Cli::parse(); + #[cfg(debug_assertions)] let cli = dbg!(Cli::parse()); match cli.command { |