|
|
|
@ -3,13 +3,10 @@ |
|
|
|
|
#[macro_use] |
|
|
|
|
extern crate serde_derive; |
|
|
|
|
#[macro_use] |
|
|
|
|
extern crate failure; |
|
|
|
|
#[macro_use] |
|
|
|
|
extern crate log; |
|
|
|
|
pub extern crate log; |
|
|
|
|
|
|
|
|
|
use clap::ArgMatches; |
|
|
|
|
use clappconfig::AppConfig; |
|
|
|
|
use failure::Fallible; |
|
|
|
|
use smart_default::SmartDefault; |
|
|
|
|
use std::collections::HashMap; |
|
|
|
|
use std::fs::OpenOptions; |
|
|
|
@ -105,14 +102,14 @@ impl AppConfig for Config { |
|
|
|
|
///
|
|
|
|
|
/// This can also be solved using `#[serde(skip)]` on the field, but sometimes that is not
|
|
|
|
|
/// possible.
|
|
|
|
|
fn configure<'a>(mut self, clap: &ArgMatches<'a>) -> Fallible<Self::Init> { |
|
|
|
|
fn configure<'a>(mut self, clap: &ArgMatches<'a>) -> anyhow::Result<Self::Init> { |
|
|
|
|
let input = clap.value_of("input").unwrap().to_string(); |
|
|
|
|
|
|
|
|
|
// Logging is initialized now - feel free to use it
|
|
|
|
|
debug!("Input: {}", input); |
|
|
|
|
|
|
|
|
|
if input.is_empty() { |
|
|
|
|
bail!("Input is required!"); |
|
|
|
|
anyhow::bail!("Input is required!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// `?` can be used to abort
|
|
|
|
@ -121,7 +118,7 @@ impl AppConfig for Config { |
|
|
|
|
debug!("Input path: {}", pb.display()); |
|
|
|
|
|
|
|
|
|
if !pb.is_file() { |
|
|
|
|
return Err(format_err!("Input is not a file!")); |
|
|
|
|
anyhow::bail!("Input is not a file!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Set offset by arg
|
|
|
|
@ -144,7 +141,7 @@ impl AppConfig for Config { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn main() -> Fallible<()> { |
|
|
|
|
fn main() -> anyhow::Result<()> { |
|
|
|
|
// Using custom version (default is CARGO_PKG_VERSION)
|
|
|
|
|
let version = format!( |
|
|
|
|
"{} by {}", |
|
|
|
@ -156,9 +153,7 @@ fn main() -> Fallible<()> { |
|
|
|
|
|
|
|
|
|
// rot13
|
|
|
|
|
|
|
|
|
|
let mut f = OpenOptions::new() |
|
|
|
|
.read(true) |
|
|
|
|
.open(main.input_file)?; |
|
|
|
|
let mut f = OpenOptions::new().read(true).open(main.input_file)?; |
|
|
|
|
|
|
|
|
|
let mut buf = String::new(); |
|
|
|
|
f.read_to_string(&mut buf)?; |
|
|
|
|