Skip to content

Commit

Permalink
Update clippy restrictions
Browse files Browse the repository at this point in the history
type: changed
  • Loading branch information
atomgardner authored and casey committed Oct 10, 2020
1 parent fa78cba commit a787d6a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 27 deletions.
5 changes: 1 addition & 4 deletions src/bytes.rs
Expand Up @@ -66,10 +66,7 @@ impl FromStr for Bytes {
fn from_str(text: &str) -> Result<Self, Self::Err> {
#[allow(clippy::trivially_copy_pass_by_ref)]
fn is_digit(c: &char) -> bool {
match c {
'0'..='9' | '.' => true,
_ => false,
}
matches!(c, '0'..='9' | '.')
}

let digits = text.chars().take_while(is_digit).collect::<String>();
Expand Down
29 changes: 14 additions & 15 deletions src/env.rs
Expand Up @@ -9,42 +9,41 @@ pub(crate) struct Env {
}

impl Env {
pub(crate) fn main() -> Self {
let dir = match env::current_dir() {
Ok(dir) => dir,
Err(error) => panic!("Failed to get current directory: {}", error),
};
pub(crate) fn main() -> Result<Self> {
let dir = env::current_dir().context(error::CurrentDirectoryGet)?;

let style = env::var_os("NO_COLOR").is_none()
&& env::var_os("TERM").as_deref() != Some(OsStr::new("dumb"));

let out_stream = OutputStream::stdout(style);
let err_stream = OutputStream::stderr(style);

Self::new(
Ok(Self::new(
dir,
env::args(),
Box::new(io::stdin()),
out_stream,
err_stream,
)
))
}

pub(crate) fn run(&mut self) -> Result<(), Error> {
pub(crate) fn run(&mut self) -> Result<()> {
#[cfg(windows)]
ansi_term::enable_ansi_support().ok();

Self::initialize_logging();

let app = Arguments::clap();
let app = {
let mut app = Arguments::clap();

let width = env::var("IMDL_TERM_WIDTH")
.ok()
.and_then(|width| width.parse::<usize>().ok());
let width = env::var("IMDL_TERM_WIDTH")
.ok()
.and_then(|width| width.parse::<usize>().ok());

if let Some(width) = width {
app = app.set_term_width(width)
}

let app = if let Some(width) = width {
app.set_term_width(width)
} else {
app
};

Expand Down
4 changes: 3 additions & 1 deletion src/error.rs
Expand Up @@ -14,10 +14,12 @@ pub(crate) enum Error {
ByteSuffix { text: String, suffix: String },
#[snafu(display("{}", source))]
Clap { source: clap::Error },
#[snafu(display("Failed to invoke command `{}`: {}", command, source,))]
#[snafu(display("Failed to invoke command `{}`: {}", command, source))]
CommandInvoke { command: String, source: io::Error },
#[snafu(display("Command `{}` returned bad exit status: {}", command, status))]
CommandStatus { command: String, status: ExitStatus },
#[snafu(display("Failed to get current directory: {}", source))]
CurrentDirectoryGet { source: io::Error },
#[snafu(display("Filename was not valid unicode: `{}`", filename.display()))]
FilenameDecode { filename: PathBuf },
#[snafu(display("Path had no file name: `{}`", path.display()))]
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
@@ -1,5 +1,6 @@
#![deny(clippy::all, clippy::pedantic, clippy::restriction)]
#![allow(
clippy::blanket_clippy_restriction_lints,
clippy::else_if_without_else,
clippy::enum_glob_use,
clippy::float_arithmetic,
Expand All @@ -14,6 +15,7 @@
clippy::missing_inline_in_public_items,
clippy::needless_pass_by_value,
clippy::non_ascii_literal,
clippy::pattern_type_mismatch,
clippy::shadow_reuse,
clippy::struct_excessive_bools,
clippy::too_many_lines,
Expand Down
10 changes: 9 additions & 1 deletion src/run.rs
Expand Up @@ -18,5 +18,13 @@ use crate::common::*;
/// be passed to `std::process::exit`, to exit the process and report its
/// failure to the system.
pub fn run() -> Result<(), i32> {
Env::main().status()
let mut env = match Env::main() {
Ok(env) => env,
Err(err) => {
eprintln!("{}", err);
return Err(EXIT_FAILURE);
}
};

env.status()
}
11 changes: 5 additions & 6 deletions src/subcommand/torrent/verify.rs
Expand Up @@ -64,14 +64,13 @@ impl Verify {

let metainfo = Metainfo::from_input(&input)?;

let content = if let Some(content) = &self.content {
content.clone()
} else {
match target {
let content = self.content.as_ref().map_or_else(
|| match target {
InputTarget::Path(path) => path.join("..").join(&metainfo.info.name).lexiclean(),
InputTarget::Stdin => PathBuf::from(&metainfo.info.name),
}
};
},
PathBuf::clone,
);

let progress_bar = if env.err().is_styled_term() && !options.quiet {
let style = ProgressStyle::default_bar()
Expand Down

0 comments on commit a787d6a

Please sign in to comment.