From ee7576fc1d9f39d92d04fb6a1387b846043d3a61 Mon Sep 17 00:00:00 2001 From: Josh Stoik Date: Tue, 8 Oct 2024 19:14:02 -0700 Subject: [PATCH 1/5] misc: replace IndexMap with BTreeMap --- bashman_core/Cargo.toml | 1 - bashman_core/src/raw.rs | 12 +++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bashman_core/Cargo.toml b/bashman_core/Cargo.toml index 9c89c9f..3c9b30f 100644 --- a/bashman_core/Cargo.toml +++ b/bashman_core/Cargo.toml @@ -14,7 +14,6 @@ argyle = "0.8.*" cargo_metadata = "=0.18.1" flate2 = "1.0.*" fyi_msg = "0.14.*" -indexmap = "2.6.*" oxford_join = "0.4.*" trimothy = "0.3.*" utc2k = "0.10.*" diff --git a/bashman_core/src/raw.rs b/bashman_core/src/raw.rs index 6fe2e10..9acebe1 100644 --- a/bashman_core/src/raw.rs +++ b/bashman_core/src/raw.rs @@ -24,14 +24,16 @@ use crate::{ DataOption, More, }; -use indexmap::IndexMap; use serde::{ Deserialize, Deserializer, }; -use std::path::{ - Path, - PathBuf, +use std::{ + collections::BTreeMap, + path::{ + Path, + PathBuf, + }, }; use trimothy::TrimMut; @@ -403,7 +405,7 @@ impl<'a> TryFrom<&'a Raw> for Command<'a> { return src.parse_single(); } - let mut subcmds: IndexMap<&'_ str, (&'_ str, &'_ str, &'_ str, Vec::>)> = src.package.metadata.subcommands.iter() + let mut subcmds: BTreeMap<&'_ str, (&'_ str, &'_ str, &'_ str, Vec::>)> = src.package.metadata.subcommands.iter() .map(|y| ( y.cmd.as_str(), From 703de4bbb9e104304e2c4fc581dc131c28433917 Mon Sep 17 00:00:00 2001 From: Josh Stoik Date: Thu, 10 Oct 2024 15:14:13 -0700 Subject: [PATCH 2/5] bump: fyi 1.1 --- bashman/Cargo.toml | 2 +- bashman_core/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bashman/Cargo.toml b/bashman/Cargo.toml index 609f7ae..a31aad6 100644 --- a/bashman/Cargo.toml +++ b/bashman/Cargo.toml @@ -66,7 +66,7 @@ path = true [dependencies] argyle = "0.8.*" -fyi_msg = "0.14.*" +fyi_msg = "1.1.*" [dependencies.bashman_core] path = "../bashman_core" diff --git a/bashman_core/Cargo.toml b/bashman_core/Cargo.toml index 3c9b30f..12bf916 100644 --- a/bashman_core/Cargo.toml +++ b/bashman_core/Cargo.toml @@ -13,7 +13,7 @@ adbyss_psl = "0.13.*" argyle = "0.8.*" cargo_metadata = "=0.18.1" flate2 = "1.0.*" -fyi_msg = "0.14.*" +fyi_msg = "1.1.*" oxford_join = "0.4.*" trimothy = "0.3.*" utc2k = "0.10.*" From 268df465ef94a96ed68ab512b493d641ca3e0c24 Mon Sep 17 00:00:00 2001 From: Josh Stoik Date: Mon, 14 Oct 2024 22:41:22 -0700 Subject: [PATCH 3/5] bump: argyle 0.10 refactor: cli parsing --- bashman/Cargo.toml | 5 ++- bashman/build.rs | 34 +++++++++++++++++++ bashman/src/main.rs | 71 ++++++++++++++++++--------------------- bashman_core/Cargo.toml | 1 - bashman_core/src/error.rs | 28 ++++++++++++--- 5 files changed, 94 insertions(+), 45 deletions(-) create mode 100644 bashman/build.rs diff --git a/bashman/Cargo.toml b/bashman/Cargo.toml index a31aad6..6e398d7 100644 --- a/bashman/Cargo.toml +++ b/bashman/Cargo.toml @@ -64,8 +64,11 @@ description = "Path to the Cargo.toml file to use." label = "" path = true +[build-dependencies] +argyle = "0.10.*" + [dependencies] -argyle = "0.8.*" +argyle = "0.10.*" fyi_msg = "1.1.*" [dependencies.bashman_core] diff --git a/bashman/build.rs b/bashman/build.rs new file mode 100644 index 0000000..a8c85f6 --- /dev/null +++ b/bashman/build.rs @@ -0,0 +1,34 @@ +/*! +# Cargo Bashman: Build +*/ + +use argyle::KeyWordsBuilder; +use std::path::PathBuf; + + + +/// # Set Up CLI Arguments. +pub fn main() { + let mut builder = KeyWordsBuilder::default(); + builder.push_keys([ + "-h", "--help", + "--no-bash", + "--no-credits", + "--no-man", + "-V", "--version", + ]); + builder.push_keys_with_values([ + "-f", "--features", + "-m", "--manifest-path", + ]); + builder.save(out_path("argyle.rs")); +} + +/// # Output Path. +/// +/// Append the sub-path to OUT_DIR and return it. +fn out_path(stub: &str) -> PathBuf { + std::fs::canonicalize(std::env::var("OUT_DIR").expect("Missing OUT_DIR.")) + .expect("Missing OUT_DIR.") + .join(stub) +} diff --git a/bashman/src/main.rs b/bashman/src/main.rs index 6658f4c..7f5783e 100644 --- a/bashman/src/main.rs +++ b/bashman/src/main.rs @@ -53,12 +53,7 @@ -use argyle::{ - Argue, - ArgyleError, - FLAG_HELP, - FLAG_VERSION, -}; +use argyle::Argument; use bashman_core::{ BashManError, FLAG_ALL, @@ -75,10 +70,10 @@ use std::path::PathBuf; fn main() { match _main() { Ok(()) => {}, - Err(BashManError::Argue(ArgyleError::WantsVersion)) => { + Err(BashManError::PrintVersion) => { println!(concat!("Cargo BashMan v", env!("CARGO_PKG_VERSION"))); }, - Err(BashManError::Argue(ArgyleError::WantsHelp)) => { helper(); }, + Err(BashManError::PrintHelp) => { helper(); }, Err(e) => { Msg::error(e.to_string()).die(1); }, } } @@ -87,41 +82,41 @@ fn main() { /// # Actual main. fn _main() -> Result<(), BashManError> { // Parse CLI arguments. - let args = Argue::new(FLAG_HELP | FLAG_VERSION).map_err(BashManError::Argue)?; - - // Check for invalid CLI options. - if let Some(boo) = args.check_keys( - &[b"--no-bash", b"--no-credits", b"--no-man"], - &[b"--features", b"--manifest-path", b"-f", b"-m"], - ) { - return Err(BashManError::InvalidCli(String::from_utf8_lossy(boo).into())); - } + let args = argyle::args() + .with_keywords(include!(concat!(env!("OUT_DIR"), "/argyle.rs"))); let mut flags: u8 = FLAG_ALL; - if args.switch(b"--no-bash") { - flags &= ! FLAG_BASH; - } - if args.switch(b"--no-credits") { - flags &= ! FLAG_CREDITS; - } - if args.switch(b"--no-man") { - flags &= ! FLAG_MAN; - } - - let features = args.option2(b"-f", b"--features").and_then(|x| std::str::from_utf8(x).ok()); - - let manifest = - if let Some(p) = args.option2_os(b"-m", b"--manifest-path") { - PathBuf::from(p) + let mut features = None; + let mut manifest = None; + for arg in args { + match arg { + Argument::Key("--no-bash") => { flags &= ! FLAG_BASH; }, + Argument::Key("--no-credits") => { flags &= ! FLAG_CREDITS; }, + Argument::Key("--no-man") => { flags &= ! FLAG_MAN; }, + + Argument::Key("-h" | "--help") => return Err(BashManError::PrintHelp), + Argument::Key("-V" | "--version") => return Err(BashManError::PrintVersion), + + Argument::KeyWithValue("-f" | "--features", s) => { features.replace(s); } + Argument::KeyWithValue("-m" | "--manifest-path", s) => { + manifest.replace(PathBuf::from(s)); + }, + + // Nothing else is expected. + Argument::Other(s) => return Err(BashManError::InvalidCli(s.into_boxed_str())), + Argument::InvalidUtf8(s) => return Err(BashManError::InvalidCli(s.to_string_lossy().into_owned().into_boxed_str())), + _ => {}, } - else { - std::env::current_dir() - .map_err(|_| BashManError::InvalidManifest)? - .join("Cargo.toml") - }; + } - bashman_core::parse(manifest, flags, features)?; + let manifest = match manifest { + Some(m) => m, + None => std::env::current_dir() + .map_err(|_| BashManError::InvalidManifest)? + .join("Cargo.toml"), + }; + bashman_core::parse(manifest, flags, features.as_deref())?; Ok(()) } diff --git a/bashman_core/Cargo.toml b/bashman_core/Cargo.toml index 12bf916..3e6da34 100644 --- a/bashman_core/Cargo.toml +++ b/bashman_core/Cargo.toml @@ -10,7 +10,6 @@ publish = false [dependencies] adbyss_psl = "0.13.*" -argyle = "0.8.*" cargo_metadata = "=0.18.1" flate2 = "1.0.*" fyi_msg = "1.1.*" diff --git a/bashman_core/src/error.rs b/bashman_core/src/error.rs index 3e76580..69ad8ad 100644 --- a/bashman_core/src/error.rs +++ b/bashman_core/src/error.rs @@ -2,49 +2,67 @@ # `Cargo BashMan` - Error */ -use argyle::ArgyleError; use std::error::Error; use std::fmt; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Eq, PartialEq)] /// # Error. pub enum BashManError { - /// # Argue Passthru. - Argue(ArgyleError), /// # Invalid Bash output directory. InvalidBashDir, + /// # Invalid Credits output directory. InvalidCreditsDir, + /// # Invalid CLI Option. InvalidCli(Box), + /// # Invalid flag. InvalidFlag, + /// # Invalid item. InvalidItem, + /// # Invalid/missing Cargo.lock. InvalidLock, + /// # Invalid Man output directory. InvalidManDir, + /// # Invalid manifest. InvalidManifest, + /// # Invalid section. InvalidSection, + /// # Invalid subcommand. InvalidSubCommand(Box), + /// # Missing subcommand. MissingSubCommand, + /// # Parse manifest. ParseManifest(Box), + /// # Write Bash. WriteBash, + /// # Write Credits. WriteCredits, + /// # Write Man. WriteMan, + /// # Write Man. WriteSubMan(Box), + + /// # Print Help (Not an Error). + PrintHelp, + + /// # Print Version (Not an Error). + PrintVersion, } impl Error for BashManError {} @@ -52,7 +70,6 @@ impl Error for BashManError {} impl fmt::Display for BashManError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Argue(src) => f.write_str(src.as_str()), Self::InvalidBashDir => f.write_str("Invalid BASH output directory."), Self::InvalidCli(s) => f.write_fmt(format_args!("Invalid/unknown CLI option: {s}")), Self::InvalidCreditsDir => f.write_str("Invalid credits output directory."), @@ -69,6 +86,7 @@ impl fmt::Display for BashManError { Self::WriteCredits => f.write_str("Unable to write CREDITS.md."), Self::WriteMan => f.write_str("Unable to write Manual(s)."), Self::WriteSubMan(s) => f.write_fmt(format_args!("Unable to write Man for {s:?}.")), + Self::PrintHelp | Self::PrintVersion => Ok(()), } } } From 934c50a082dbca92fe7b0d3e793cb730c8bbbc3d Mon Sep 17 00:00:00 2001 From: Josh Stoik Date: Thu, 17 Oct 2024 13:04:57 -0700 Subject: [PATCH 4/5] bump: 0.5.1 --- bashman/Cargo.toml | 2 +- bashman_core/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bashman/Cargo.toml b/bashman/Cargo.toml index 6e398d7..0631638 100644 --- a/bashman/Cargo.toml +++ b/bashman/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-bashman" -version = "0.5.0" +version = "0.5.1" license = "WTFPL" authors = ["Josh Stoik "] edition = "2021" diff --git a/bashman_core/Cargo.toml b/bashman_core/Cargo.toml index 3e6da34..c1b5c01 100644 --- a/bashman_core/Cargo.toml +++ b/bashman_core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bashman_core" -version = "0.5.0" +version = "0.5.1" license = "WTFPL" authors = ["Josh Stoik "] edition = "2021" From 3442970daf771afc82e5ea22e15e26c7e0a95b75 Mon Sep 17 00:00:00 2001 From: Josh Stoik Date: Thu, 17 Oct 2024 13:06:23 -0700 Subject: [PATCH 5/5] build: 0.5.1 --- CREDITS.md | 16 ++++++++-------- release/man/cargo-bashman.1 | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CREDITS.md b/CREDITS.md index e6598b2..ca2d1cf 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -1,15 +1,15 @@ # Project Dependencies Package: cargo-bashman - Version: 0.5.0 - Generated: 2024-10-08 19:58:02 UTC + Version: 0.5.1 + Generated: 2024-10-17 20:05:20 UTC | Package | Version | Author(s) | License | | ---- | ---- | ---- | ---- | -| [adbyss_psl](https://github.com/Blobfolio/adbyss) | 0.13.0 | [Josh Stoik](mailto:josh@blobfolio.com) | WTFPL | +| [adbyss_psl](https://github.com/Blobfolio/adbyss) | 0.13.1 | [Josh Stoik](mailto:josh@blobfolio.com) | WTFPL | | [adler2](https://github.com/oyvindln/adler2) | 2.0.0 | [Jonas Schievink](mailto:jonasschievink@gmail.com) and [oyvindln](mailto:oyvindln@users.noreply.github.com) | 0BSD, Apache-2.0, or MIT | | [ahash](https://github.com/tkaitchuck/ahash) | 0.8.11 | [Tom Kaitchuck](mailto:tom.kaitchuck@gmail.com) | Apache-2.0 or MIT | -| [argyle](https://github.com/Blobfolio/argyle) | 0.8.1 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL | -| [bashman_core](https://github.com/Blobfolio/bashman) | 0.5.0 | [Josh Stoik](mailto:josh@blobfolio.com) | WTFPL | +| [argyle](https://github.com/Blobfolio/argyle) | 0.10.0 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL | +| [bashman_core](https://github.com/Blobfolio/bashman) | 0.5.1 | [Josh Stoik](mailto:josh@blobfolio.com) | WTFPL | | [camino](https://github.com/camino-rs/camino) | 1.1.9 | [Without Boats](mailto:saoirse@without.boats), [Ashley Williams](mailto:ashley666ashley@gmail.com), [Steve Klabnik](mailto:steve@steveklabnik.com), and [Rain](mailto:rain@sunshowers.io) | Apache-2.0 or MIT | | [cargo-platform](https://github.com/rust-lang/cargo) | 0.1.8 | | Apache-2.0 or MIT | | [cargo_metadata](https://github.com/oli-obk/cargo_metadata) | 0.18.1 | [Oliver Schneider](mailto:git-spam-no-reply9815368754983@oli-obk.de) | MIT | @@ -19,7 +19,7 @@ | [displaydoc](https://github.com/yaahc/displaydoc) | 0.2.5 | [Jane Lusby](mailto:jlusby@yaah.dev) | Apache-2.0 or MIT | | [equivalent](https://github.com/cuviper/equivalent) | 1.0.1 | | Apache-2.0 or MIT | | [flate2](https://github.com/rust-lang/flate2-rs) | 1.0.34 | [Alex Crichton](mailto:alex@alexcrichton.com) and [Josh Triplett](mailto:josh@joshtriplett.org) | Apache-2.0 or MIT | -| [fyi_msg](https://github.com/Blobfolio/fyi) | 0.14.1 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL | +| [fyi_msg](https://github.com/Blobfolio/fyi) | 1.1.1 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL | | [hashbrown](https://github.com/rust-lang/hashbrown) | 0.15.0 | [Amanieu d'Antras](mailto:amanieu@gmail.com) | Apache-2.0 or MIT | | [icu_collections](https://github.com/unicode-org/icu4x) | 1.5.0 | The ICU4X Project Developers | Unicode-3.0 | | [icu_locid](https://github.com/unicode-org/icu4x) | 1.5.0 | The ICU4X Project Developers | Unicode-3.0 | @@ -38,13 +38,13 @@ | [memchr](https://github.com/BurntSushi/memchr) | 2.7.4 | [Andrew Gallant](mailto:jamslam@gmail.com) and bluss | MIT or Unlicense | | [miniz_oxide](https://github.com/Frommi/miniz_oxide/tree/master/miniz_oxide) | 0.8.0 | [Frommi](mailto:daniil.liferenko@gmail.com) and [oyvindln](mailto:oyvindln@users.noreply.github.com) | Apache-2.0, MIT, or Zlib | | [oxford_join](https://github.com/Blobfolio/oxford_join) | 0.4.0 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL | -| [proc-macro2](https://github.com/dtolnay/proc-macro2) | 1.0.87 | [David Tolnay](mailto:dtolnay@gmail.com) and [Alex Crichton](mailto:alex@alexcrichton.com) | Apache-2.0 or MIT | +| [proc-macro2](https://github.com/dtolnay/proc-macro2) | 1.0.88 | [David Tolnay](mailto:dtolnay@gmail.com) and [Alex Crichton](mailto:alex@alexcrichton.com) | Apache-2.0 or MIT | | [quote](https://github.com/dtolnay/quote) | 1.0.37 | [David Tolnay](mailto:dtolnay@gmail.com) | Apache-2.0 or MIT | | [ryu](https://github.com/dtolnay/ryu) | 1.0.18 | [David Tolnay](mailto:dtolnay@gmail.com) | Apache-2.0 or BSL-1.0 | | [semver](https://github.com/dtolnay/semver) | 1.0.23 | [David Tolnay](mailto:dtolnay@gmail.com) | Apache-2.0 or MIT | | [serde](https://github.com/serde-rs/serde) | 1.0.210 | [Erick Tryzelaar](mailto:erick.tryzelaar@gmail.com) and [David Tolnay](mailto:dtolnay@gmail.com) | Apache-2.0 or MIT | | [serde_derive](https://github.com/serde-rs/serde) | 1.0.210 | [Erick Tryzelaar](mailto:erick.tryzelaar@gmail.com) and [David Tolnay](mailto:dtolnay@gmail.com) | Apache-2.0 or MIT | -| [serde_json](https://github.com/serde-rs/json) | 1.0.128 | [Erick Tryzelaar](mailto:erick.tryzelaar@gmail.com) and [David Tolnay](mailto:dtolnay@gmail.com) | Apache-2.0 or MIT | +| [serde_json](https://github.com/serde-rs/json) | 1.0.129 | [Erick Tryzelaar](mailto:erick.tryzelaar@gmail.com) and [David Tolnay](mailto:dtolnay@gmail.com) | Apache-2.0 or MIT | | [serde_spanned](https://github.com/toml-rs/toml) | 0.6.8 | | Apache-2.0 or MIT | | [smallvec](https://github.com/servo/rust-smallvec) | 1.13.2 | The Servo Project Developers | Apache-2.0 or MIT | | [stable_deref_trait](https://github.com/storyyeller/stable_deref_trait) | 1.2.0 | [Robert Grosse](mailto:n210241048576@gmail.com) | Apache-2.0 or MIT | diff --git a/release/man/cargo-bashman.1 b/release/man/cargo-bashman.1 index 9a49d65..127fc86 100644 --- a/release/man/cargo-bashman.1 +++ b/release/man/cargo-bashman.1 @@ -1,6 +1,6 @@ -.TH "CARGO BASHMAN" "1" "October 2024" "cargo\-bashman v0.5.0" "User Commands" +.TH "CARGO BASHMAN" "1" "October 2024" "cargo\-bashman v0.5.1" "User Commands" .SH NAME -CARGO BASHMAN \- Manual page for cargo\-bashman v0.5.0. +CARGO BASHMAN \- Manual page for cargo\-bashman v0.5.1. .SH DESCRIPTION A Cargo plugin to generate BASH completions and MAN pages. .SS USAGE: