Skip to content

Commit b63d089

Browse files
committed
release: 0.1.4
2 parents af066fc + 6690bda commit b63d089

File tree

6 files changed

+39
-59
lines changed

6 files changed

+39
-59
lines changed

bashman/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-bashman"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
license = "WTFPL"
55
authors = ["Josh Stoik <[email protected]>"]
66
edition = "2018"
@@ -47,7 +47,7 @@ path = true
4747
[dependencies]
4848
chrono = "0.4.*"
4949
indexmap = "1.6.*"
50-
libdeflater = "0.5.*"
50+
libdeflater = "0.6.*"
5151

5252
[dependencies.toml]
5353
version = "0.5.*"

bashman/src/agree.rs

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -721,22 +721,14 @@ impl Agree {
721721
/// choosing, using the file name "{bin}.bash".
722722
pub fn write_bash<P>(&self, dir: P) -> Result<(), String>
723723
where P: AsRef<Path> {
724-
let mut path = std::fs::canonicalize(dir.as_ref()).map_err(|_| format!(
725-
"Missing BASH completion directory: {:?}",
726-
dir.as_ref()
727-
))?;
728-
729-
if path.is_dir() {
730-
path.push([&self.bin, ".bash"].concat());
731-
write_to(&path, self.bash().as_bytes(), false)
732-
.map_err(|_| format!(
733-
"Unable to write BASH completions: {:?}",
734-
path
735-
))
736-
}
737-
else {
738-
Err(format!("Invalid BASH completion directory: {:?}", dir.as_ref()))
739-
}
724+
let mut path = std::fs::canonicalize(dir.as_ref())
725+
.ok()
726+
.filter(|x| x.is_dir())
727+
.ok_or_else(|| format!("Invalid BASH completion directory: {:?}", dir.as_ref()))?;
728+
729+
path.push([&self.bin, ".bash"].concat());
730+
write_to(&path, self.bash().as_bytes(), false)
731+
.map_err(|_| format!("Unable to write BASH completions: {:?}", path))
740732
}
741733

742734
/// # Write MAN Page!
@@ -753,23 +745,15 @@ impl Agree {
753745
/// either the "{bin}.1" or "{bin}.1.gz" version, not both. ;)
754746
pub fn write_man<P>(&self, dir: P) -> Result<(), String>
755747
where P: AsRef<Path> {
756-
let mut path = std::fs::canonicalize(dir.as_ref()).map_err(|_| format!(
757-
"Missing MAN directory: {:?}",
758-
dir.as_ref()
759-
))?;
748+
let mut path = std::fs::canonicalize(dir.as_ref())
749+
.ok()
750+
.filter(|x| x.is_dir())
751+
.ok_or_else(|| format!("Invalid MAN directory: {:?}", dir.as_ref()))?;
760752

761753
// The main file.
762-
if path.is_dir() {
763-
path.push([&self.bin, ".1"].concat());
764-
write_to(&path, self.man().as_bytes(), true)
765-
.map_err(|_| format!(
766-
"Unable to write MAN page: {:?}",
767-
path
768-
))?;
769-
}
770-
else {
771-
return Err(format!("Invalid MAN directory: {:?}", dir.as_ref()))
772-
}
754+
path.push([&self.bin, ".1"].concat());
755+
write_to(&path, self.man().as_bytes(), true)
756+
.map_err(|_| format!("Unable to write MAN page: {:?}", path))?;
773757

774758
// Write subcommand pages.
775759
for (bin, man) in self.args.iter()
@@ -780,10 +764,7 @@ impl Agree {
780764
path.pop();
781765
path.push([&self.bin, "-", &bin, ".1"].concat());
782766
write_to(&path, man.as_bytes(), true)
783-
.map_err(|_| format!(
784-
"Unable to write MAN page: {:?}",
785-
path
786-
))?;
767+
.map_err(|_| format!("Unable to write SUB-MAN page: {:?}", path))?;
787768
}
788769

789770
Ok(())
@@ -1040,16 +1021,14 @@ complete -F chooser_{fname} -o bashdefault -o default {bname}
10401021
}
10411022

10421023
// Generated ARGUMENTS Section.
1043-
{
1044-
self.args.iter()
1045-
.filter_map(AgreeKind::if_arg)
1046-
.for_each(|x| {
1047-
pre.push(
1048-
AgreeSection::new(&[&x.name, ":"].concat(), true)
1049-
.with_item(AgreeKind::paragraph(&x.description))
1050-
);
1051-
});
1052-
}
1024+
self.args.iter()
1025+
.filter_map(AgreeKind::if_arg)
1026+
.for_each(|x| {
1027+
pre.push(
1028+
AgreeSection::new(&[&x.name, ":"].concat(), true)
1029+
.with_item(AgreeKind::paragraph(&x.description))
1030+
);
1031+
});
10531032

10541033
// Generated SUBCOMMANDS Section.
10551034
{
@@ -1136,9 +1115,9 @@ fn man_tagline(short: Option<&str>, long: Option<&str>, value: Option<&str>) ->
11361115
/// This writes data to a file, optionally recursing to save a `GZipped`
11371116
/// version (for MAN pages).
11381117
fn write_to(file: &PathBuf, data: &[u8], compress: bool) -> Result<(), ()> {
1139-
let mut out = std::fs::File::create(file).map_err(|_| ())?;
1140-
out.write_all(data).map_err(|_| ())?;
1141-
out.flush().map_err(|_| ())?;
1118+
std::fs::File::create(file)
1119+
.and_then(|mut out| out.write_all(data).and_then(|_| out.flush()))
1120+
.map_err(|_| ())?;
11421121

11431122
// Save a compressed copy?
11441123
if compress {

bashman/src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#![allow(clippy::cast_possible_truncation)]
2525
#![allow(clippy::cast_precision_loss)]
2626
#![allow(clippy::cast_sign_loss)]
27+
#![allow(clippy::map_err_ignore)]
2728
#![allow(clippy::missing_errors_doc)]
2829
#![allow(clippy::module_name_repetitions)]
2930

@@ -215,17 +216,15 @@ where P: AsRef<Path> {
215216
/// absolute, they are realigned to be relative to the manifest directory.
216217
fn resolve_path(path: Option<&Value>, dir: &PathBuf) -> Result<PathBuf, String> {
217218
path.and_then(Value::as_str)
218-
.map_or(
219-
Ok(dir.clone()),
219+
.map_or_else(
220+
|| Ok(dir.clone()),
220221
|path|
221-
if path.starts_with('/') {
222-
std::fs::canonicalize(path).map_err(|e| e.to_string())
223-
}
222+
if path.starts_with('/') { std::fs::canonicalize(path) }
224223
else {
225224
let mut tmp: PathBuf = dir.clone();
226225
tmp.push(path);
227-
std::fs::canonicalize(tmp).map_err(|e| e.to_string())
228-
}
226+
std::fs::canonicalize(tmp)
227+
}.map_err(|e| e.to_string())
229228
)
230229
}
231230

bashman/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ This work is free. You can redistribute it and/or modify it under the terms of t
273273
#![allow(clippy::cast_possible_truncation)]
274274
#![allow(clippy::cast_precision_loss)]
275275
#![allow(clippy::cast_sign_loss)]
276+
#![allow(clippy::map_err_ignore)]
276277
#![allow(clippy::missing_errors_doc)]
277278
#![allow(clippy::module_name_repetitions)]
278279

justfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ version:
153153
@_init:
154154
[ ! -f "{{ justfile_directory() }}/Cargo.lock" ] || rm "{{ justfile_directory() }}/Cargo.lock"
155155
cargo update
156+
cargo outdated -w
156157
157158
158159
# Fix file/directory permissions.

release/man/cargo-bashman.1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
.TH "CARGO BASHMAN" "1" "November 2020" "Cargo BashMan v0.1.3" "User Commands"
1+
.TH "CARGO BASHMAN" "1" "November 2020" "Cargo BashMan v0.1.4" "User Commands"
22
.SH NAME
3-
Cargo BashMan \- Manual page for cargo\-bashman v0.1.3.
3+
Cargo BashMan \- Manual page for cargo\-bashman v0.1.4.
44
.SH DESCRIPTION
55
BashMan is a Cargo plugin that helps you generate BASH completions and/or MAN pages for your Rust project.
66
.SS USAGE:

0 commit comments

Comments
 (0)