Skip to content

Commit 0fe73af

Browse files
committed
release: 0.3.1
2 parents db4bcc6 + 4bc28d6 commit 0fe73af

File tree

7 files changed

+229
-123
lines changed

7 files changed

+229
-123
lines changed

CREDITS.md

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,37 @@
11
# Project Dependencies
22
Package: cargo-bashman
3-
Version: 0.3.0
4-
Generated: 2021-12-03 18:32:59 UTC
3+
Version: 0.3.1
4+
Generated: 2021-12-04 19:43:08 UTC
55

66
| Package | Version | Author(s) | License |
77
| ---- | ---- | ---- | ---- |
8-
| [aho-corasick](https://github.com/BurntSushi/aho-corasick) | 0.7.18 | [Andrew Gallant](mailto:[email protected]) | MIT OR Unlicense |
9-
| [ansi_term](https://github.com/ogham/rust-ansi-term) | 0.12.1 | [email protected]; [Ryan Scheel (Havvy)](mailto:[email protected]); [Josh Triplett](mailto:[email protected]) | MIT |
10-
| [anyhow](https://github.com/dtolnay/anyhow) | 1.0.51 | [David Tolnay](mailto:[email protected]) | Apache-2.0 OR MIT |
8+
| [aho-corasick](https://github.com/BurntSushi/aho-corasick) | 0.7.18 | [Andrew Gallant](mailto:[email protected]) | MIT or Unlicense |
119
| [argyle](https://github.com/Blobfolio/argyle) | 0.5.1 | [Blobfolio, LLC.](mailto:[email protected]) | WTFPL |
12-
| [atty](https://github.com/softprops/atty) | 0.2.14 | [softprops](mailto:[email protected]) | MIT |
13-
| [bashman_core](https://github.com/Blobfolio/bashman) | 0.3.0 | [Josh Stoik](mailto:[email protected]) | WTFPL |
14-
| [bitflags](https://github.com/bitflags/bitflags) | 1.3.2 | The Rust Project Developers | Apache-2.0 OR MIT |
15-
| [bstr](https://github.com/BurntSushi/bstr) | 0.2.17 | [Andrew Gallant](mailto:[email protected]) | Apache-2.0 OR MIT |
16-
| [camino](https://github.com/withoutboats/camino) | 1.0.5 | [Without Boats](mailto:[email protected]); [Ashley Williams](mailto:[email protected]); [Steve Klabnik](mailto:[email protected]); [Rain](mailto:[email protected]) | Apache-2.0 OR MIT |
17-
| [cargo-license](https://github.com/onur/cargo-license) | 0.4.2 | [Onur Aslan](mailto:[email protected]) | MIT |
18-
| [cargo-platform](https://github.com/rust-lang/cargo) | 0.1.2 | The Cargo Project Developers | Apache-2.0 OR MIT |
10+
| [bashman_core](https://github.com/Blobfolio/bashman) | 0.3.1 | [Josh Stoik](mailto:[email protected]) | WTFPL |
11+
| [camino](https://github.com/withoutboats/camino) | 1.0.5 | [Without Boats](mailto:[email protected]), [Ashley Williams](mailto:[email protected]), [Steve Klabnik](mailto:[email protected]), and [Rain](mailto:[email protected]) | Apache-2.0 or MIT |
12+
| [cargo-platform](https://github.com/rust-lang/cargo) | 0.1.2 | The Cargo Project Developers | Apache-2.0 or MIT |
1913
| [cargo_metadata](https://github.com/oli-obk/cargo_metadata) | 0.14.1 | [Oliver Schneider](mailto:[email protected]) | MIT |
20-
| [clap](https://github.com/clap-rs/clap) | 2.34.0 | [Kevin K.](mailto:[email protected]) | MIT |
21-
| [csv](https://github.com/BurntSushi/rust-csv) | 1.1.6 | [Andrew Gallant](mailto:[email protected]) | MIT OR Unlicense |
22-
| [csv-core](https://github.com/BurntSushi/rust-csv) | 0.1.10 | [Andrew Gallant](mailto:[email protected]) | MIT OR Unlicense |
2314
| [dactyl](https://github.com/Blobfolio/dactyl) | 0.2.1 | [Blobfolio, LLC.](mailto:[email protected]) | WTFPL |
2415
| [fyi_msg](https://github.com/Blobfolio/fyi) | 0.9.2 | [Blobfolio, LLC.](mailto:[email protected]) | WTFPL |
25-
| [getopts](https://github.com/rust-lang/getopts) | 0.2.21 | The Rust Project Developers | Apache-2.0 OR MIT |
26-
| [hashbrown](https://github.com/rust-lang/hashbrown) | 0.11.2 | [Amanieu d'Antras](mailto:[email protected]) | Apache-2.0 OR MIT |
27-
| [heck](https://github.com/withoutboats/heck) | 0.3.3 | [Without Boats](mailto:[email protected]) | Apache-2.0 OR MIT |
28-
| [hermit-abi](https://github.com/hermitcore/libhermit-rs) | 0.1.19 | Stefan Lankes | Apache-2.0 OR MIT |
29-
| [indexmap](https://github.com/bluss/indexmap) | 1.7.0 | bluss; [Josh Stone](mailto:[email protected]) | Apache-2.0 OR MIT |
30-
| [itoa](https://github.com/dtolnay/itoa) | 0.4.8 | [David Tolnay](mailto:[email protected]) | Apache-2.0 OR MIT |
31-
| [lazy_static](https://github.com/rust-lang-nursery/lazy-static.rs) | 1.4.0 | [Marvin Löbel](mailto:[email protected]) | Apache-2.0 OR MIT |
32-
| [libc](https://github.com/rust-lang/libc) | 0.2.108 | The Rust Project Developers | Apache-2.0 OR MIT |
16+
| [hashbrown](https://github.com/rust-lang/hashbrown) | 0.11.2 | [Amanieu d'Antras](mailto:[email protected]) | Apache-2.0 or MIT |
17+
| [indexmap](https://github.com/bluss/indexmap) | 1.7.0 | bluss and [Josh Stone](mailto:[email protected]) | Apache-2.0 or MIT |
18+
| [itoa](https://github.com/dtolnay/itoa) | 0.4.8 | [David Tolnay](mailto:[email protected]) | Apache-2.0 or MIT |
3319
| [libdeflate-sys](https://github.com/adamkewley/libdeflater) | 0.7.3 | [Adam Kewley](mailto:[email protected]) | Apache-2.0 |
3420
| [libdeflater](https://github.com/adamkewley/libdeflater) | 0.7.3 | [Adam Kewley](mailto:[email protected]) | Apache-2.0 |
35-
| [memchr](https://github.com/BurntSushi/memchr) | 2.4.1 | [Andrew Gallant](mailto:[email protected]); bluss | MIT OR Unlicense |
36-
| [num-traits](https://github.com/rust-num/num-traits) | 0.2.14 | The Rust Project Developers | Apache-2.0 OR MIT |
37-
| [proc-macro-error](https://gitlab.com/CreepySkeleton/proc-macro-error) | 1.0.4 | [CreepySkeleton](mailto:[email protected]) | Apache-2.0 OR MIT |
38-
| [proc-macro-error-attr](https://gitlab.com/CreepySkeleton/proc-macro-error) | 1.0.4 | [CreepySkeleton](mailto:[email protected]) | Apache-2.0 OR MIT |
39-
| [proc-macro2](https://github.com/dtolnay/proc-macro2) | 1.0.32 | [David Tolnay](mailto:[email protected]); [Alex Crichton](mailto:[email protected]) | Apache-2.0 OR MIT |
40-
| [quote](https://github.com/dtolnay/quote) | 1.0.10 | [David Tolnay](mailto:[email protected]) | Apache-2.0 OR MIT |
41-
| [regex](https://github.com/rust-lang/regex) | 1.5.4 | The Rust Project Developers | Apache-2.0 OR MIT |
42-
| [regex-automata](https://github.com/BurntSushi/regex-automata) | 0.1.10 | [Andrew Gallant](mailto:[email protected]) | MIT OR Unlicense |
43-
| [regex-syntax](https://github.com/rust-lang/regex) | 0.6.25 | The Rust Project Developers | Apache-2.0 OR MIT |
44-
| [ryu](https://github.com/dtolnay/ryu) | 1.0.6 | [David Tolnay](mailto:[email protected]) | Apache-2.0 OR BSL-1.0 |
45-
| [semver](https://github.com/dtolnay/semver) | 1.0.4 | [David Tolnay](mailto:[email protected]) | Apache-2.0 OR MIT |
46-
| [serde](https://github.com/serde-rs/serde) | 1.0.130 | [Erick Tryzelaar](mailto:[email protected]); [David Tolnay](mailto:[email protected]) | Apache-2.0 OR MIT |
47-
| [serde_derive](https://github.com/serde-rs/serde) | 1.0.130 | [Erick Tryzelaar](mailto:[email protected]); [David Tolnay](mailto:[email protected]) | Apache-2.0 OR MIT |
48-
| [serde_json](https://github.com/serde-rs/json) | 1.0.72 | [Erick Tryzelaar](mailto:[email protected]); [David Tolnay](mailto:[email protected]) | Apache-2.0 OR MIT |
49-
| [strsim](https://github.com/dguo/strsim-rs) | 0.8.0 | [Danny Guo](mailto:[email protected]) | MIT |
50-
| [structopt](https://github.com/TeXitoi/structopt) | 0.3.25 | [Guillaume Pinot](mailto:[email protected]); others | Apache-2.0 OR MIT |
51-
| [structopt-derive](https://github.com/TeXitoi/structopt) | 0.4.18 | [Guillaume Pinot](mailto:[email protected]) | Apache-2.0 OR MIT |
52-
| [syn](https://github.com/dtolnay/syn) | 1.0.82 | [David Tolnay](mailto:[email protected]) | Apache-2.0 OR MIT |
53-
| [textwrap](https://github.com/mgeisler/textwrap) | 0.11.0 | [Martin Geisler](mailto:[email protected]) | MIT |
54-
| [toml](https://github.com/alexcrichton/toml-rs) | 0.5.8 | [Alex Crichton](mailto:[email protected]) | Apache-2.0 OR MIT |
55-
| [unicode-segmentation](https://github.com/unicode-rs/unicode-segmentation) | 1.8.0 | [kwantam](mailto:[email protected]); [Manish Goregaokar](mailto:[email protected]) | Apache-2.0 OR MIT |
56-
| [unicode-width](https://github.com/unicode-rs/unicode-width) | 0.1.9 | [kwantam](mailto:[email protected]); [Manish Goregaokar](mailto:[email protected]) | Apache-2.0 OR MIT |
57-
| [unicode-xid](https://github.com/unicode-rs/unicode-xid) | 0.2.2 | [erick.tryzelaar](mailto:[email protected]); [kwantam](mailto:[email protected]); [Manish Goregaokar](mailto:[email protected]) | Apache-2.0 OR MIT |
21+
| [memchr](https://github.com/BurntSushi/memchr) | 2.4.1 | [Andrew Gallant](mailto:[email protected]) and bluss | MIT or Unlicense |
22+
| [num-traits](https://github.com/rust-num/num-traits) | 0.2.14 | The Rust Project Developers | Apache-2.0 or MIT |
23+
| [once_cell](https://github.com/matklad/once_cell) | 1.8.0 | [Aleksey Kladov](mailto:[email protected]) | Apache-2.0 or MIT |
24+
| [oxford_join](https://github.com/Blobfolio/oxford_join) | 0.2.0 | [Blobfolio, LLC.](mailto:[email protected]) | WTFPL |
25+
| [proc-macro2](https://github.com/dtolnay/proc-macro2) | 1.0.32 | [David Tolnay](mailto:[email protected]) and [Alex Crichton](mailto:[email protected]) | Apache-2.0 or MIT |
26+
| [quote](https://github.com/dtolnay/quote) | 1.0.10 | [David Tolnay](mailto:[email protected]) | Apache-2.0 or MIT |
27+
| [regex](https://github.com/rust-lang/regex) | 1.5.4 | The Rust Project Developers | Apache-2.0 or MIT |
28+
| [regex-syntax](https://github.com/rust-lang/regex) | 0.6.25 | The Rust Project Developers | Apache-2.0 or MIT |
29+
| [ryu](https://github.com/dtolnay/ryu) | 1.0.6 | [David Tolnay](mailto:[email protected]) | Apache-2.0 or BSL-1.0 |
30+
| [semver](https://github.com/dtolnay/semver) | 1.0.4 | [David Tolnay](mailto:[email protected]) | Apache-2.0 or MIT |
31+
| [serde](https://github.com/serde-rs/serde) | 1.0.130 | [Erick Tryzelaar](mailto:[email protected]) and [David Tolnay](mailto:[email protected]) | Apache-2.0 or MIT |
32+
| [serde_derive](https://github.com/serde-rs/serde) | 1.0.130 | [Erick Tryzelaar](mailto:[email protected]) and [David Tolnay](mailto:[email protected]) | Apache-2.0 or MIT |
33+
| [serde_json](https://github.com/serde-rs/json) | 1.0.72 | [Erick Tryzelaar](mailto:[email protected]) and [David Tolnay](mailto:[email protected]) | Apache-2.0 or MIT |
34+
| [syn](https://github.com/dtolnay/syn) | 1.0.82 | [David Tolnay](mailto:[email protected]) | Apache-2.0 or MIT |
35+
| [toml](https://github.com/alexcrichton/toml-rs) | 0.5.8 | [Alex Crichton](mailto:[email protected]) | Apache-2.0 or MIT |
36+
| [unicode-xid](https://github.com/unicode-rs/unicode-xid) | 0.2.2 | [erick.tryzelaar](mailto:[email protected]), [kwantam](mailto:[email protected]), and [Manish Goregaokar](mailto:[email protected]) | Apache-2.0 or MIT |
5837
| [utc2k](https://github.com/Blobfolio/utc2k) | 0.3.1 | [Blobfolio, LLC.](mailto:[email protected]) | WTFPL |
59-
| [vec_map](https://github.com/contain-rs/vec-map) | 0.8.2 | [Alex Crichton](mailto:[email protected]); [Jorge Aparicio](mailto:[email protected]); [Alexis Beingessner](mailto:[email protected]); Brian Anderson; tbu-; Manish Goregaokar; [Aaron Turon](mailto:[email protected]); Adolfo Ochagavía; Niko Matsakis; Steven Fackler; [Chase Southwood](mailto:[email protected]); Eduard Burtescu; Florian Wilkens; Félix Raimundo; Tibor Benke; [Markus Siemens](mailto:[email protected]); [Josh Branchaud](mailto:[email protected]); [Huon Wilson](mailto:[email protected]); [Corey Farwell](mailto:[email protected]); Aaron Liblong; [Nick Cameron](mailto:[email protected]); [Patrick Walton](mailto:[email protected]); Felix S Klock II; [Andrew Paseltiner](mailto:[email protected]); [Sean McArthur](mailto:[email protected]); Vadim Petrochenkov | Apache-2.0 OR MIT |
60-
| [winapi](https://github.com/retep998/winapi-rs) | 0.3.9 | [Peter Atashian](mailto:[email protected]) | Apache-2.0 OR MIT |
61-
| [winapi-i686-pc-windows-gnu](https://github.com/retep998/winapi-rs) | 0.4.0 | [Peter Atashian](mailto:[email protected]) | Apache-2.0 OR MIT |
62-
| [winapi-x86_64-pc-windows-gnu](https://github.com/retep998/winapi-rs) | 0.4.0 | [Peter Atashian](mailto:[email protected]) | Apache-2.0 OR MIT |

bashman/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-bashman"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
license = "WTFPL"
55
authors = ["Josh Stoik <[email protected]>"]
66
edition = "2021"

bashman_core/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bashman_core"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
license = "WTFPL"
55
authors = ["Josh Stoik <[email protected]>"]
66
edition = "2021"
@@ -11,11 +11,12 @@ publish = false
1111

1212
[dependencies]
1313
argyle = "0.5.*"
14-
cargo-license = "0.4.*"
1514
cargo_metadata = "0.14.*"
1615
fyi_msg = "0.9.*"
1716
indexmap = "1.7.*"
1817
libdeflater = "0.7.*"
18+
once_cell = "1.8.*"
19+
oxford_join = "0.2.*"
1920
regex = "1.5.*"
2021
utc2k = "0.3.*"
2122

bashman_core/src/credits.rs

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/*!
2+
# `Cargo BashMan` — Dependency Credits
3+
4+
This is largely a trimmed-down version of `cargo_license`. Our needs are much
5+
narrower than theirs.
6+
*/
7+
8+
use cargo_metadata::{
9+
DependencyKind,
10+
DepKindInfo,
11+
MetadataCommand,
12+
Node,
13+
NodeDep,
14+
Package,
15+
PackageId,
16+
};
17+
use crate::BashManError;
18+
use once_cell::sync::Lazy;
19+
use oxford_join::OxfordJoin;
20+
use regex::Regex;
21+
use std::{
22+
collections::{
23+
HashMap,
24+
HashSet,
25+
},
26+
path::Path,
27+
};
28+
29+
30+
31+
32+
#[derive(Debug)]
33+
/// # Dependency.
34+
pub(super) struct Dependency {
35+
pub(super) name: String,
36+
pub(super) version: String,
37+
pub(super) authors: String,
38+
pub(super) license: String,
39+
pub(super) link: Option<String>,
40+
}
41+
42+
impl From<Package> for Dependency {
43+
fn from(mut src: Package) -> Self {
44+
strip_markdown(&mut src.name);
45+
let mut version = src.version.to_string();
46+
strip_markdown(&mut version);
47+
48+
Self {
49+
name: src.name,
50+
version,
51+
authors: nice_author(src.authors),
52+
license: src.license.map_or_else(String::new, |l| nice_license(&l)),
53+
link: src.repository,
54+
}
55+
}
56+
}
57+
58+
59+
60+
/// # Get Dependencies.
61+
pub(super) fn get_dependencies(src: &Path) -> Result<Vec<Dependency>, BashManError> {
62+
let metadata = {
63+
let mut cmd = MetadataCommand::new();
64+
cmd.manifest_path(&src);
65+
cmd.exec().map_err(|_| BashManError::InvalidManifest)?
66+
};
67+
68+
// Parse out all of the package IDs in the dependency tree, excluding dev-
69+
// and build-deps.
70+
let deps = {
71+
let resolve = metadata.resolve.as_ref()
72+
.ok_or(BashManError::InvalidManifest)?;
73+
74+
// Pull dependencies by package.
75+
let deps: HashMap<&PackageId, &Vec<NodeDep>> = resolve
76+
.nodes
77+
.iter()
78+
.map(|Node { id, deps, .. }| (id, deps))
79+
.collect();
80+
81+
// Build a list of all unique, normal dependencies.
82+
let mut out: HashSet<&PackageId> = HashSet::new();
83+
let stack = &mut resolve.root.as_ref()
84+
.map_or_else(
85+
|| metadata.workspace_members.iter().collect(),
86+
|root| vec![root]
87+
);
88+
89+
while let Some(package_id) = stack.pop() {
90+
if out.insert(package_id) {
91+
stack.extend(deps[package_id].iter().filter_map(
92+
|NodeDep { pkg, dep_kinds, .. }|
93+
if dep_kinds.iter().any(|DepKindInfo { kind, .. }| *kind == DependencyKind::Normal) {
94+
Some(pkg)
95+
}
96+
else { None }
97+
));
98+
}
99+
}
100+
101+
out
102+
};
103+
104+
// One final time around to pull the relevant package details for each
105+
// corresponding ID.
106+
let mut out: Vec<Dependency> = metadata.packages.into_iter()
107+
.filter(|p| deps.contains(&p.id))
108+
.map(Dependency::from)
109+
.collect();
110+
111+
out.sort_by(|a, b| a.name.to_ascii_lowercase().cmp(&b.name.to_ascii_lowercase()));
112+
113+
Ok(out)
114+
}
115+
116+
/// # Normalize Licenses.
117+
fn nice_license(raw: &str) -> String {
118+
let mut raw = raw.replace(" OR ", "/");
119+
strip_markdown(&mut raw);
120+
let mut list: Vec<&str> = raw.split('/').map(str::trim).collect();
121+
list.sort_unstable();
122+
list.dedup();
123+
list.oxford_or().into_owned()
124+
}
125+
126+
/// # Normalize Authors.
127+
fn nice_author(raw: Vec<String>) -> String {
128+
static RE1: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\[|\]|\||\(|\))").unwrap());
129+
static RE2: Lazy<Regex> = Lazy::new(|| Regex::new(r"(.+?) <([^>]+)>").unwrap());
130+
131+
let list: Vec<String> = raw.into_iter()
132+
.map(|x| {
133+
let y = RE1.replace_all(&x, "");
134+
let z = RE2.replace_all(y.trim(), "[$1](mailto:$2)");
135+
if x == z { x }
136+
else { z.into_owned() }
137+
})
138+
.collect();
139+
list.oxford_and().into_owned()
140+
}
141+
142+
/// # Lightly Sanitize.
143+
///
144+
/// Remove `[] <> () |` to help with later markdown display.
145+
fn strip_markdown(raw: &mut String) {
146+
static RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\[|\]|\||<|>|\(|\))").unwrap());
147+
148+
let alt = RE.replace_all(raw.trim(), "");
149+
if raw != &alt {
150+
*raw = alt.into_owned();
151+
}
152+
}
153+
154+
#[cfg(test)]
155+
mod tests {
156+
use super::*;
157+
158+
#[test]
159+
fn t_strip_markdown() {
160+
let mut raw: String = r" H(E)L[L]O <W>O|RLD ".to_string();
161+
strip_markdown(&mut raw);
162+
assert_eq!(raw, "HELLO WORLD");
163+
}
164+
}

0 commit comments

Comments
 (0)