From b91222e6a7689748b2c45a3e8c771f137023f5b1 Mon Sep 17 00:00:00 2001 From: Ruben Serrano Izquierdo Date: Sat, 17 Feb 2024 12:12:20 +0100 Subject: [PATCH 1/3] Allow launch command as `last` positional argument --- Cargo.lock | 224 +++++++++++++++++++------------------- Cargo.toml | 5 +- completions/_envio | 5 +- completions/envio.bash | 2 +- src/bin/envio/cli.rs | 26 ++++- src/bin/envio/commands.rs | 4 +- 6 files changed, 139 insertions(+), 127 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 949bf00..01c320e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,6 +81,54 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "arc-swap" version = "1.6.0" @@ -93,7 +141,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi 0.1.19", + "hermit-abi", "libc", "winapi", ] @@ -137,12 +185,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitflags" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "487f1e0fcbe47deb8b0574e646def1c903389d95241dd1bbcc6ce4a715dfc0c1" - [[package]] name = "block-buffer" version = "0.10.4" @@ -249,17 +291,24 @@ dependencies = [ [[package]] name = "clap" -version = "4.1.11" +version = "4.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42dfd32784433290c51d92c438bb72ea5063797fc3cc9a21a8c4346bebbb2098" +checksum = "c918d541ef2913577a0f9566e9ce27cb35b6df072075769e0b26cb5a554520da" dependencies = [ - "bitflags 2.0.2", + "clap_builder", "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f3e7391dad68afb0c2ede1bf619f579a3dc9c2ec67f089baa397123a2f3d1eb" +dependencies = [ + "anstream", + "anstyle", "clap_lex", - "is-terminal", - "once_cell", - "strsim", - "termcolor", + "strsim 0.11.0", ] [[package]] @@ -273,25 +322,21 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.1.9" +version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fddf67631444a3a3e3e5ac51c36a5e01335302de677bd78759eaa90ab1f46644" +checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" dependencies = [ "heck", - "proc-macro-error", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.16", ] [[package]] name = "clap_lex" -version = "0.3.3" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "033f6b7a4acb1f358c742aaca805c939ee73b4c6209ae4318ec7aca81c42e646" -dependencies = [ - "os_str_bytes", -] +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "clap_mangen" @@ -313,6 +358,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "colored" version = "2.0.0" @@ -395,7 +446,7 @@ version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" dependencies = [ - "bitflags 1.3.2", + "bitflags", "crossterm_winapi", "libc", "mio", @@ -477,7 +528,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.3", + "syn 2.0.16", ] [[package]] @@ -494,7 +545,7 @@ checksum = "631569015d0d8d54e6c241733f944042623ab6df7bc3be7466874b05fcdb1c5f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.3", + "syn 2.0.16", ] [[package]] @@ -606,27 +657,6 @@ dependencies = [ "url", ] -[[package]] -name = "errno" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" -dependencies = [ - "errno-dragonfly", - "libc", - "winapi", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "find-crate" version = "0.6.3" @@ -781,7 +811,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57539732fbe58eacdb984734b72b470ed0bca3ab7a49813271878567025ac44f" dependencies = [ - "bitflags 1.3.2", + "bitflags", "cfg-if", "conv", "cstr-argument", @@ -847,12 +877,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hermit-abi" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" - [[package]] name = "hkdf" version = "0.12.3" @@ -993,7 +1017,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "strsim", + "strsim 0.10.0", "syn 1.0.109", "unic-langid", ] @@ -1082,7 +1106,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4bf420bd01f298a3ed8f57af9babedb296b4edfc1dbd8b159cee883aa90edaa" dependencies = [ - "bitflags 1.3.2", + "bitflags", "crossterm", "dyn-clone", "lazy_static", @@ -1111,17 +1135,6 @@ dependencies = [ "unic-langid", ] -[[package]] -name = "io-lifetimes" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09270fd4fa1111bc614ed2246c7ef56239a3063d5be0d1ec3b589c505d400aeb" -dependencies = [ - "hermit-abi 0.3.1", - "libc", - "windows-sys 0.45.0", -] - [[package]] name = "io_tee" version = "0.1.1" @@ -1134,18 +1147,6 @@ version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" -[[package]] -name = "is-terminal" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8687c819457e979cc940d09cb16e42a1bf70aa6b60a549de6d3a62a0ee90c69e" -dependencies = [ - "hermit-abi 0.3.1", - "io-lifetimes", - "rustix", - "windows-sys 0.45.0", -] - [[package]] name = "itoa" version = "1.0.6" @@ -1193,12 +1194,6 @@ dependencies = [ "cc", ] -[[package]] -name = "linux-raw-sys" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" - [[package]] name = "lock_api" version = "0.4.9" @@ -1309,12 +1304,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" -[[package]] -name = "os_str_bytes" -version = "6.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" - [[package]] name = "parking_lot" version = "0.12.1" @@ -1440,9 +1429,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.52" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -1533,7 +1522,7 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags 1.3.2", + "bitflags", ] [[package]] @@ -1664,20 +1653,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustix" -version = "0.36.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fe885c3a125aa45213b68cc1472a49880cb5923dc23f522ad2791b882228778" -dependencies = [ - "bitflags 1.3.2", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys", - "windows-sys 0.45.0", -] - [[package]] name = "rustls" version = "0.20.8" @@ -1799,7 +1774,7 @@ version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" dependencies = [ - "bitflags 1.3.2", + "bitflags", "core-foundation", "core-foundation-sys", "libc", @@ -1845,7 +1820,7 @@ checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" dependencies = [ "proc-macro2", "quote", - "syn 2.0.3", + "syn 2.0.16", ] [[package]] @@ -1964,6 +1939,12 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strsim" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" + [[package]] name = "strum" version = "0.24.1" @@ -2002,9 +1983,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.3" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8234ae35e70582bfa0f1fedffa6daa248e41dd045310b19800c4a36382c8f60" +checksum = "a6f671d4b5ffdb8eadec19c0ae67fe2639df8684bd7bc4b83d986b8db549cf01" dependencies = [ "proc-macro2", "quote", @@ -2050,7 +2031,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.3", + "syn 2.0.16", ] [[package]] @@ -2286,6 +2267,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "version-compare" version = "0.1.1" @@ -2480,6 +2467,15 @@ dependencies = [ "windows-targets 0.48.0", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-targets" version = "0.42.2" @@ -2697,5 +2693,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.3", + "syn 2.0.16", ] diff --git a/Cargo.toml b/Cargo.toml index 13b0d81..5e482ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ path = "src/lib.rs" age = "0.9.1" bincode = "1.3.3" chrono = { version = "0.4.33", features = ["serde"] } -clap = { version = "4.1.8", features = ["derive"] } +clap = { version = "4.3.24", features = ["derive"] } colored = "2.0.0" comfy-table = "6.1.4" dirs = "5.0.0" @@ -43,6 +43,3 @@ chrono = "0.4.33" clap = { version = "4.1.8", features = ["derive"] } clap_mangen = "0.2.9" clap_complete = "4.2.1" - - - diff --git a/completions/_envio b/completions/_envio index b27f377..eb4201d 100755 --- a/completions/_envio +++ b/completions/_envio @@ -63,11 +63,12 @@ _arguments "${_arguments_options[@]}" \ ;; (launch) _arguments "${_arguments_options[@]}" \ -'-c+[]:COMMAND: ' \ -'--command=[]:COMMAND: ' \ +'-c+[]:STRING_COMMAND: ' \ +'--command=[]:STRING_COMMAND: ' \ '-h[Print help]' \ '--help[Print help]' \ ':profile_name:' \ +'*::COMMAND:' \ && ret=0 ;; (remove) diff --git a/completions/envio.bash b/completions/envio.bash index 3e3c6e8..ef07c9b 100755 --- a/completions/envio.bash +++ b/completions/envio.bash @@ -399,7 +399,7 @@ _envio() { return 0 ;; envio__launch) - opts="-c -h --command --help " + opts="-c -h --command --help [COMMAND]..." if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 diff --git a/src/bin/envio/cli.rs b/src/bin/envio/cli.rs index c1091eb..deb4325 100755 --- a/src/bin/envio/cli.rs +++ b/src/bin/envio/cli.rs @@ -1,6 +1,6 @@ use clap::Parser; -#[derive(Parser)] +#[derive(Parser, Debug)] /* * Clap Application */ @@ -77,13 +77,13 @@ pub enum Command { #[command( name = "launch", about = "Run a command with the environment variables from a profile", - override_usage = "envio launch [OPTIONS]" + override_usage = "envio launch <--command STRING_COMMAND | -- COMMAND>" )] Launch { #[arg(required = true)] profile_name: String, - #[arg(required = true, long = "command", short = 'c')] - command: String, + #[command(flatten)] + command: LaunchCommandArg, }, #[command( name = "remove", @@ -155,3 +155,21 @@ pub enum Command { verbose: Option, }, } + +#[derive(clap::Args, Debug)] +#[group(required = true, multiple = false)] +pub struct LaunchCommandArg { + #[arg(long = "command", short = 'c', name = "STRING_COMMAND")] + argument: Option, + #[arg(last = true, name = "COMMAND")] + positional: Vec, +} + +impl LaunchCommandArg { + pub fn value(&self) -> Vec<&str> { + if let Some(command) = self.argument.as_ref() { + return command.split_whitespace().collect(); + } + self.positional.iter().map(|s| s.as_str()).collect() + } +} diff --git a/src/bin/envio/commands.rs b/src/bin/envio/commands.rs index f00818a..406dc1b 100755 --- a/src/bin/envio/commands.rs +++ b/src/bin/envio/commands.rs @@ -333,7 +333,7 @@ impl Command { profile_name, command, } => { - let split_command = command.split_whitespace().collect::>(); + let split_command = command.value(); let program = split_command[0]; let args = &split_command[1..]; @@ -354,7 +354,7 @@ impl Command { return; }; - let output = std::process::Command::new(&program) + let output = std::process::Command::new(program) .envs(profile.envs) .args(args) .output() From 5bd4f31c9a8e5ef09ebba30d34527a78d582cb31 Mon Sep 17 00:00:00 2001 From: Humble Penguin Date: Sat, 17 Feb 2024 19:35:46 +0500 Subject: [PATCH 2/3] Bump MSRV to 1.70.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5e482ca..329490e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "envio" version = "0.5.1" -rust-version = "1.64.0" +rust-version = "1.70.0" description = "A Modern And Secure CLI Tool For Managing Environment Variables" edition = "2021" authors = ["Humble Penguin "] From 05a02110e6fe82147547f0c2996ceb5c80f28dad Mon Sep 17 00:00:00 2001 From: Humble Penguin Date: Sat, 17 Feb 2024 19:50:29 +0500 Subject: [PATCH 3/3] 1.70.0 causes build errors so bump to 1.76.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 329490e..12216d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "envio" version = "0.5.1" -rust-version = "1.70.0" +rust-version = "1.76.0" description = "A Modern And Secure CLI Tool For Managing Environment Variables" edition = "2021" authors = ["Humble Penguin "]