diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2022-06-22 22:45:49 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2022-06-22 22:45:49 -0400 |
| commit | 0c2c4c38cb0da4d63d36c8032aabf7612068aef0 (patch) | |
| tree | df5484a6a343b8fc8c5557930adfdfdcb70d128e | |
| parent | 9ada1147fa46a4ac6eba3e90758f4a30dd638aa9 (diff) | |
| -rw-r--r-- | Cargo.lock | 135 | ||||
| -rw-r--r-- | Cargo.toml | 8 | ||||
| -rw-r--r-- | src/main.rs | 25 |
3 files changed, 76 insertions, 92 deletions
@@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "atty" version = "0.2.14" @@ -13,40 +15,38 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "clap" -version = "3.0.0-beta.2" +version = "3.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bd1061998a501ee7d4b6d449020df3266ca3124b941ec56cf2005c3779ca142" +checksum = "9f1fe12880bae935d142c8702d500c63a4e8634b6c3c57ad72bf978fc7b6249a" dependencies = [ "atty", "bitflags", "clap_derive", + "clap_lex", "indexmap", - "lazy_static", - "os_str_bytes", + "once_cell", "strsim", "termcolor", "textwrap", - "unicode-width", - "vec_map", ] [[package]] name = "clap_derive" -version = "3.0.0-beta.2" +version = "3.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "370f715b81112975b1b69db93e0b56ea4cd4e5002ac43b2da8474106a54096a1" +checksum = "ed6db9e867166a43a53f7199b5e4d1f522a1e5bd626654be263c999ce59df39a" dependencies = [ "heck", "proc-macro-error", @@ -56,6 +56,15 @@ dependencies = [ ] [[package]] +name = "clap_lex" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87eba3c8c7f42ef17f6c659fc7416d0f4758cd3e58861ee63c5fa4a4dde649e4" +dependencies = [ + "os_str_bytes", +] + +[[package]] name = "envdir-helper" version = "0.2.0" dependencies = [ @@ -67,55 +76,52 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.9.1" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" +checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" [[package]] name = "heck" -version = "0.3.2" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" -dependencies = [ - "unicode-segmentation", -] +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" -version = "0.1.17" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] [[package]] name = "indexmap" -version = "1.6.1" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", "hashbrown", ] [[package]] -name = "lazy_static" -version = "1.4.0" +name = "libc" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] -name = "libc" -version = "0.2.81" +name = "once_cell" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" +checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" [[package]] name = "os_str_bytes" -version = "2.4.0" +version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb2e1c3ee07430c2cf76151675e583e0f19985fa6efae47d6848a3e2c824f85" +checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" [[package]] name = "proc-macro-error" @@ -143,27 +149,27 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.24" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.8" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df" +checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" dependencies = [ "proc-macro2", ] [[package]] name = "shlex" -version = "0.1.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" +checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" [[package]] name = "strsim" @@ -173,47 +179,44 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.55" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a571a711dddd09019ccc628e1b17fe87c59b09d513c06c026877aa708334f37a" +checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] name = "termcolor" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ "winapi-util", ] [[package]] name = "textwrap" -version = "0.12.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "203008d98caf094106cfaba70acfed15e18ed3ddb7d94e49baec153a2b462789" -dependencies = [ - "unicode-width", -] +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thiserror" -version = "1.0.22" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e9ae34b84616eedaaf1e9dd6026dbe00dcafa92aa0c8077cb69df1fcfe5e53e" +checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.22" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56" +checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" dependencies = [ "proc-macro2", "quote", @@ -221,34 +224,16 @@ dependencies = [ ] [[package]] -name = "unicode-segmentation" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" - -[[package]] -name = "unicode-width" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" - -[[package]] -name = "unicode-xid" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" - -[[package]] -name = "vec_map" -version = "0.8.2" +name = "unicode-ident" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" [[package]] name = "version_check" -version = "0.9.2" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "winapi" @@ -5,7 +5,7 @@ authors = ["Owen Jacobson <owen@grimoire.ca>"] edition = "2018" [dependencies] -clap = "~3.0.0-beta.2" -libc = "~0.2.40" -shlex = "~0.1.1" -thiserror = "~1.0" +clap = { version = "3.2.6", features = ["derive"] } +libc = "0.2.126" +shlex = "1.1.0" +thiserror = "1.0.31" diff --git a/src/main.rs b/src/main.rs index df34235..530adac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,13 @@ use std::env; use std::ffi::OsString; use std::fmt::Debug; -use std::fs::{DirEntry, metadata, read_dir, read_to_string}; +use std::fs::{metadata, read_dir, read_to_string, DirEntry}; use std::io; use std::path::{Path, PathBuf}; -use std::process::{Command, Stdio, ExitStatus}; +use std::process::{Command, ExitStatus, Stdio}; use std::string::FromUtf8Error; -use clap::Clap; +use clap::Parser; use thiserror::Error; /// Load environment variables from DIR (or ~/.envdir). @@ -27,8 +27,7 @@ use thiserror::Error; /// eval "$(envdir-helper)" /// /// The generated output is compatible with sh, and thus with bash and zsh. -#[derive(Clap)] -#[clap(version=env!("CARGO_PKG_VERSION"))] +#[derive(Parser)] struct Opts { /// Directory to read environment variables from [default: ~/.envdir] envdir: Option<PathBuf>, @@ -112,13 +111,13 @@ fn detect_env_script(path: &Path) -> Result<ExportScript, PathStringError> { fn no_export_env_script(name: &str, content: &str) -> String { let name = shlex::quote(name); - let content= shlex::quote(content); + let content = shlex::quote(content); format!("{}={}", name, content) } fn export_env_script(name: &str, content: &str) -> String { let name = shlex::quote(name); - let content= shlex::quote(content); + let content = shlex::quote(content); format!("{}={}; export {}", name, content, name) } @@ -132,9 +131,9 @@ enum PathStringError { fn path_to_string(path: &Path) -> Result<&str, PathStringError> { use PathStringError::*; - let file_name = path.file_name() - .ok_or_else(|| NamelessPath(path.into()))?; - file_name.to_str() + let file_name = path.file_name().ok_or_else(|| NamelessPath(path.into()))?; + file_name + .to_str() .ok_or_else(|| NonUnicodePath(file_name.into())) } @@ -145,7 +144,7 @@ enum EnvContentError { #[error("program produced non-UTF-8 output: {0}")] NonUnicodeOutput(#[from] FromUtf8Error), #[error("program {0:?} exited with status: {1}")] - ProgramFailed(PathBuf, ExitStatus) + ProgramFailed(PathBuf, ExitStatus), } fn env_content(path: &Path) -> Result<String, EnvContentError> { @@ -158,7 +157,7 @@ fn env_content(path: &Path) -> Result<String, EnvContentError> { if content.ends_with("\n") { content.pop(); } - + Ok(content) } @@ -181,7 +180,7 @@ fn env_program_content(path: &Path) -> Result<String, EnvContentError> { .stdout(Stdio::piped()) .stderr(Stdio::inherit()) .output()?; - + if output.status.success() { let output = String::from_utf8(output.stdout)?; Ok(output) |
