Skip to content

Commit

Permalink
Bump version and fix fsays to use it
Browse files Browse the repository at this point in the history
  • Loading branch information
mgattozzi committed Nov 1, 2022
1 parent 675f227 commit 570d876
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ferris-says"
version = "0.2.1"
version = "0.3.1"
authors = ["Michael Gattozzi <[email protected]>"]
description = "A Rust flavored replacement for the classic cowsay"
documentation = "https://docs.rs/ferris-says"
Expand Down
7 changes: 3 additions & 4 deletions fsays/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "fsays"
version = "0.1.0"
version = "0.3.0"
authors = ["Michael Gattozzi <[email protected]>"]
edition = "2018"
edition = "2021"
description = "A Rust flavored replacement for the classic cowsay"
documentation = "https://docs.rs/ferris-says"
homepage = "https://github.com/mgattozzi/ferris-says"
Expand All @@ -20,6 +20,5 @@ license = "MIT/Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ferris-says = "0.2"
ferris-says = { version = "0.3", path = ".." }
clap = "2.25"
error-chain = "0.10"
46 changes: 17 additions & 29 deletions fsays/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#![recursion_limit = "1024"]

extern crate clap;
extern crate ferris_says;
#[macro_use]
extern crate error_chain;

use clap::{App, Arg};
use ferris_says::*;
use std::error::Error;
use std::fs::File;
use std::io::{stderr, stdin, stdout, BufReader, BufWriter, Read, Write};
use std::process::exit;

error_chain! {}
use std::str;

// Constants used for err messages
const ARGS: &str = "Invalid argument passed to fsays caused an error";
Expand All @@ -25,19 +20,11 @@ fn main() {

writeln!(stderr, "error: {}", e).expect(STDERR);

for e in e.iter().skip(1) {
writeln!(stderr, "caused by: {}", e).expect(STDERR);
}

if let Some(backtrace) = e.backtrace() {
writeln!(stderr, "backtrace: {:?}", backtrace).expect(STDERR);
}

exit(1);
}
}

fn run() -> Result<()> {
fn run() -> Result<(), Box<dyn Error>> {
let args = App::new("Ferris Says")
.version("0.1")
.author("Michael Gattozzi <[email protected]>")
Expand Down Expand Up @@ -68,7 +55,7 @@ fn run() -> Result<()> {
)
.get_matches();

let width = args.value_of("WIDTH").unwrap().parse().chain_err(|| ARGS)?;
let width = args.value_of("WIDTH").unwrap().parse().map_err(|_| ARGS)?;

let stdin = stdin();
let stdout = stdout();
Expand All @@ -79,42 +66,43 @@ fn run() -> Result<()> {
// Read in files and say them with Ferris
let reader = files
.map(|i| {
let reader = BufReader::new(File::open(i).chain_err(|| INPUT)?);
Ok(reader
.bytes()
.fold(Ok(Vec::new()), |a: Result<Vec<u8>>, b| {
let reader = BufReader::new(File::open(i).map_err(|_| INPUT)?);
Ok(reader.bytes().fold(
Ok(Vec::new()),
|a: Result<Vec<u8>, Box<dyn Error>>, b| {
if let Ok(mut a) = a {
a.push(b.chain_err(|| INPUT)?);
a.push(b.map_err(|_| INPUT)?);
Ok(a)
} else {
a
}
})?)
},
)?)
})
.collect::<Vec<Result<Vec<u8>>>>();
.collect::<Vec<Result<Vec<u8>, Box<dyn Error>>>>();
for i in reader {
say(&i?, width, &mut writer).chain_err(|| STDOUT)?;
say(str::from_utf8(&i?)?, width, &mut writer).map_err(|_| STDOUT)?;
}

Ok(())
} else if let Some(other_args) = args.values_of("TEXT") {
let s = other_args.collect::<Vec<&str>>().join(" ");
say(s.as_bytes(), width, &mut writer).chain_err(|| STDOUT)?;
say(&s, width, &mut writer).map_err(|_| STDOUT)?;

Ok(())
} else {
let reader = BufReader::new(stdin.lock()).bytes().fold(
Ok(Vec::new()),
|a: Result<Vec<u8>>, b| {
|a: Result<Vec<u8>, Box<dyn Error>>, b| {
if let Ok(mut a) = a {
a.push(b.chain_err(|| INPUT)?);
a.push(b.map_err(|_| INPUT)?);
Ok(a)
} else {
a
}
},
)?;
say(&reader, width, &mut writer).chain_err(|| STDOUT)?;
say(str::from_utf8(&reader)?, width, &mut writer).map_err(|_| STDOUT)?;

Ok(())
}
Expand Down

0 comments on commit 570d876

Please sign in to comment.