From 59cd51b132895512483cce0fccf64f3093b094f6 Mon Sep 17 00:00:00 2001 From: Sam Hedin Date: Mon, 22 Jun 2020 16:50:52 +0200 Subject: [PATCH] Clippy --- crates/nu-cli/src/cli.rs | 4 +-- crates/nu-cli/src/commands/autoenv.rs | 4 +-- crates/nu-cli/src/commands/autoenv_trust.rs | 2 +- crates/nu-cli/src/commands/autoenv_untrust.rs | 28 +++++++++++-------- .../src/env/directory_specific_environment.rs | 12 ++++---- crates/nu-cli/src/env/environment.rs | 2 +- crates/nu-cli/src/env/environment_syncer.rs | 4 +-- 7 files changed, 30 insertions(+), 26 deletions(-) diff --git a/crates/nu-cli/src/cli.rs b/crates/nu-cli/src/cli.rs index 97deb47a65..26790dcbf8 100644 --- a/crates/nu-cli/src/cli.rs +++ b/crates/nu-cli/src/cli.rs @@ -238,7 +238,7 @@ pub fn create_default_context( syncer.load_environment(); let mut context = Context::basic()?; - syncer.sync_env_vars(&mut context)?; + syncer.sync_env_vars(&mut context); syncer.sync_path_vars(&mut context); { @@ -677,7 +677,7 @@ pub async fn cli( // TODO: make sure config is cached so we don't path this load every call // FIXME: we probably want to be a bit more graceful if we can't set the environment syncer.reload(); - syncer.sync_env_vars(&mut context)?; + syncer.sync_env_vars(&mut context); syncer.sync_path_vars(&mut context); match line { diff --git a/crates/nu-cli/src/commands/autoenv.rs b/crates/nu-cli/src/commands/autoenv.rs index ae79ce097a..c1fb83f1b3 100644 --- a/crates/nu-cli/src/commands/autoenv.rs +++ b/crates/nu-cli/src/commands/autoenv.rs @@ -4,8 +4,8 @@ use nu_errors::ShellError; use nu_protocol::{ReturnSuccess, Signature, UntaggedValue}; use serde::Deserialize; use serde::Serialize; -use std::path::PathBuf; use std::io::Read; +use std::path::PathBuf; pub struct Autoenv; @@ -26,7 +26,7 @@ impl Trusted { .read(true) .create(true) .write(true) - .open(config_path.clone()) + .open(config_path) { Ok(p) => p, Err(_) => { diff --git a/crates/nu-cli/src/commands/autoenv_trust.rs b/crates/nu-cli/src/commands/autoenv_trust.rs index 0ea9e0c587..4a6454c233 100644 --- a/crates/nu-cli/src/commands/autoenv_trust.rs +++ b/crates/nu-cli/src/commands/autoenv_trust.rs @@ -5,7 +5,7 @@ use nu_errors::ShellError; use nu_protocol::SyntaxShape; use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value}; use std::hash::{Hash, Hasher}; -use std::{fs, collections::hash_map::DefaultHasher, path::PathBuf}; +use std::{collections::hash_map::DefaultHasher, fs, path::PathBuf}; pub struct AutoenvTrust; #[async_trait] diff --git a/crates/nu-cli/src/commands/autoenv_untrust.rs b/crates/nu-cli/src/commands/autoenv_untrust.rs index 6f193db2f4..2d336d11a7 100644 --- a/crates/nu-cli/src/commands/autoenv_untrust.rs +++ b/crates/nu-cli/src/commands/autoenv_untrust.rs @@ -1,3 +1,4 @@ +use super::autoenv::Trusted; use crate::commands::WholeStreamCommand; use crate::prelude::*; use nu_errors::ShellError; @@ -5,10 +6,8 @@ use nu_protocol::SyntaxShape; use nu_protocol::{Primitive, ReturnSuccess, Signature, UntaggedValue, Value}; use std::io::Read; use std::{fs, path::PathBuf}; -use super::autoenv::Trusted; pub struct AutoenvUnTrust; - #[async_trait] impl WholeStreamCommand for AutoenvUnTrust { fn name(&self) -> &str { @@ -16,7 +15,11 @@ impl WholeStreamCommand for AutoenvUnTrust { } fn signature(&self) -> Signature { - Signature::build("autoenv untrust").optional("dir", SyntaxShape::String, "Directory to disallow") + Signature::build("autoenv untrust").optional( + "dir", + SyntaxShape::String, + "Directory to disallow", + ) } fn usage(&self) -> &str { @@ -28,7 +31,6 @@ impl WholeStreamCommand for AutoenvUnTrust { args: CommandArgs, registry: &CommandRegistry, ) -> Result { - let tag = args.call_info.name_tag.clone(); let file_to_untrust = match args.call_info.evaluate(registry).await?.args.nth(0) { Some(Value { @@ -52,19 +54,21 @@ impl WholeStreamCommand for AutoenvUnTrust { .read(true) .create(true) .write(true) - .open(config_path.clone()) { - Ok(p) => p, - Err(_) => { - return Err(ShellError::untagged_runtime_error("Couldn't open nu-env.toml")); - } - }; + .open(config_path.clone()) + { + Ok(p) => p, + Err(_) => { + return Err(ShellError::untagged_runtime_error( + "Couldn't open nu-env.toml", + )); + } + }; let mut doc = String::new(); file.read_to_string(&mut doc)?; let mut allowed: Trusted = toml::from_str(doc.as_str()).unwrap_or_else(|_| Trusted::new()); - let file_to_untrust = file_to_untrust.to_string_lossy().to_string(); allowed.files.remove(&file_to_untrust); @@ -81,4 +85,4 @@ impl WholeStreamCommand for AutoenvUnTrust { fn examples(&self) -> Vec { Vec::new() } -} \ No newline at end of file +} diff --git a/crates/nu-cli/src/env/directory_specific_environment.rs b/crates/nu-cli/src/env/directory_specific_environment.rs index d0323f7365..49f1c4269b 100644 --- a/crates/nu-cli/src/env/directory_specific_environment.rs +++ b/crates/nu-cli/src/env/directory_specific_environment.rs @@ -2,11 +2,12 @@ use crate::commands::{self, autoenv::Trusted}; use commands::autoenv; use indexmap::{IndexMap, IndexSet}; use std::{ + collections::hash_map::DefaultHasher, ffi::OsString, fmt::Debug, + hash::{Hash, Hasher}, io::{Error, ErrorKind}, path::PathBuf, - hash::{Hash, Hasher}, collections::hash_map::DefaultHasher }; type EnvKey = String; @@ -39,9 +40,10 @@ impl DirectorySpecificEnvironment { let mut hasher = DefaultHasher::new(); content.hash(&mut hasher); if trusted.files.get(wdirenv.to_str().unwrap()) - == Some(&hasher.finish().to_string()) { - return Ok(content.parse::()?); - } + == Some(&hasher.finish().to_string()) + { + return Ok(content.parse::()?); + } } } Err(Error::new(ErrorKind::Other, "No trusted directories")) @@ -55,7 +57,7 @@ impl DirectorySpecificEnvironment { //Start in the current directory, then traverse towards the root with working_dir to see if we are in a subdirectory of a valid directory. while let Some(wdir) = working_dir { if let Ok(toml_doc) = self.toml_if_directory_is_trusted(wdir.to_path_buf()) { - toml_doc + toml_doc .get("env") .ok_or_else(|| Error::new(ErrorKind::InvalidData, "env section missing"))? .as_table() diff --git a/crates/nu-cli/src/env/environment.rs b/crates/nu-cli/src/env/environment.rs index ec24076431..8df68f035c 100644 --- a/crates/nu-cli/src/env/environment.rs +++ b/crates/nu-cli/src/env/environment.rs @@ -47,7 +47,7 @@ impl Environment { } } - pub fn from_config(configuration: &T) -> Environment { + pub fn from_config(configuration: &T) -> Environment { let env = configuration.env(); let path = configuration.path(); Environment { diff --git a/crates/nu-cli/src/env/environment_syncer.rs b/crates/nu-cli/src/env/environment_syncer.rs index a37a0dc1ea..1f1d34d99a 100644 --- a/crates/nu-cli/src/env/environment_syncer.rs +++ b/crates/nu-cli/src/env/environment_syncer.rs @@ -3,7 +3,6 @@ use crate::data::config::{Conf, NuConfig}; use crate::env::environment::{Env, Environment}; use parking_lot::Mutex; use std::sync::Arc; -use nu_errors::ShellError; pub struct EnvironmentSyncer { pub env: Arc>>, @@ -42,7 +41,7 @@ impl EnvironmentSyncer { environment.morph(&*self.config); } - pub fn sync_env_vars(&mut self, ctx: &mut Context) -> Result<(), ShellError> { + pub fn sync_env_vars(&mut self, ctx: &mut Context) { let mut environment = self.env.lock(); environment.maintain_directory_environment().ok(); @@ -72,7 +71,6 @@ impl EnvironmentSyncer { } } } - Ok(()) } pub fn sync_path_vars(&mut self, ctx: &mut Context) {