Skip to content

Commit

Permalink
Merge #50 from task/clippy
Browse files Browse the repository at this point in the history
Fix clippy warnings
  • Loading branch information
MrDogeBro committed Apr 15, 2022
2 parents ed94615 + 8deee4a commit a982edd
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn config(option: Option<String>, new_value: Option<String>) -> Result<i32>
config.options.create_missing_directories = string::to_bool(&new_value)?;
value = "create_missing_directories";
}
_ => return Err(anyhow!(format!("Option not found or is not valid. Use quicknav config to view available options.")))
_ => return Err(anyhow!("Option not found or is not valid. Use quicknav config to view available options.".to_string()))
}

println!(
Expand All @@ -43,7 +43,7 @@ pub fn config(option: Option<String>, new_value: Option<String>) -> Result<i32>
]);
}
_ => {
return Err(anyhow!(format!("Option not found or is not valid. Use quicknav config to view available options.")));
return Err(anyhow!("Option not found or is not valid. Use quicknav config to view available options.".to_string()));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn edit(
shortcut_conf.location = cwd.to_owned();
} else if location.starts_with(&env::var("HOME").unwrap()) {
shortcut_conf.location =
str::replace(&location, &env::var("HOME").unwrap(), "~");
str::replace(location, &env::var("HOME").unwrap(), "~");
} else {
shortcut_conf.location = str::replace(
&fs::canonicalize(location)?.display().to_string(),
Expand Down
14 changes: 7 additions & 7 deletions src/commands/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ pub fn get(location: String, search: bool) -> Result<i32> {

for shortcut in &config.shortcuts {
if shortcut.calls.iter().any(|c| c.starts_with(&location)) {
for c in shortcut.calls.to_owned() {
for c in shortcut.calls.iter().cloned() {
if c.starts_with(&location) {
possible_shortcuts.push(c.to_string());
possible_shortcuts.push(c);
break;
}
}
Expand All @@ -28,10 +28,10 @@ pub fn get(location: String, search: bool) -> Result<i32> {

for shortcut in config.shortcuts {
if shortcut.calls.iter().any(|c| c == &location) {
let shortcut_location = shortcut.location.replace("~", &var("HOME").unwrap());
let shortcut_location = shortcut.location.replace('~', &var("HOME").unwrap());

if Path::new(&shortcut_location).exists() {
println!("{}", shortcut.location.replace("~", &var("HOME").unwrap()));
println!("{}", shortcut.location.replace('~', &var("HOME").unwrap()));
return Ok(0);
}

Expand All @@ -44,12 +44,12 @@ pub fn get(location: String, search: bool) -> Result<i32> {

create_dir_all(&shortcut_location)?;

println!("{}", shortcut.location.replace("~", &var("HOME").unwrap()));
println!("{}", shortcut.location.replace('~', &var("HOME").unwrap()));
return Ok(0);
}
}

Err(anyhow!(format!(
Err(anyhow!(
"Navigation shortcut not found. Use quicknav list to view all your shortcuts."
)))
))
}
4 changes: 2 additions & 2 deletions src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn get_profile(profile: &str, command: &str) -> Result<String> {
if profile == "default" {
let shell_profile = include_str!("../../shell/default.txt");

if command.len() > 0 {
if !command.is_empty() {
let new_command = format!("function {}", command);
return Ok(shell_profile.replace("function nav", &new_command));
}
Expand All @@ -20,7 +20,7 @@ fn get_profile(profile: &str, command: &str) -> Result<String> {
} else if profile == "fish" {
let shell_profile = include_str!("../../shell/fish.txt");

if command.len() > 0 {
if !command.is_empty() {
let new_command = format!("function {}", command);
return Ok(shell_profile.replace("function nav", &new_command));
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
mod add;
mod edit;
mod config;
mod edit;
mod get;
mod init;
mod list;
mod remove;

pub use add::add;
pub use edit::edit;
pub use add::add_call;
pub use config::config;
pub use edit::edit;
pub use get::get;
pub use init::init;
pub use list::list;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn remove_call(call: String) -> Result<i32> {
)));
}

if config.shortcuts[shortcut_index].calls.iter().count() == 1 {
if config.shortcuts[shortcut_index].calls.len() == 1 {
return Err(anyhow!(format!(
"Shortcuts must have one call. Please either add a new call before trying to remove one or remove the whole shortcut using {} {}",
"quicknav remove".yellow(),
Expand Down
10 changes: 1 addition & 9 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Shortcut {
pub calls: Vec<String>,
}

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct Options {
#[serde(default)]
pub create_missing_directories: bool,
Expand All @@ -25,14 +25,6 @@ pub struct Config {
pub options: Options,
}

impl Default for Options {
fn default() -> Options {
Options {
create_missing_directories: false,
}
}
}

impl Config {
fn generate() -> Result<i32> {
let config_folder = var("XDG_CONFIG_HOME")
Expand Down
22 changes: 11 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,33 @@ fn main() {
fn run() -> Result<i32> {
match Quicknav::from_args_safe() {
Ok(cmd) => match cmd {
Quicknav::Get { location, search } => return commands::get(location, search),
Quicknav::List { shortcut } => return commands::list(shortcut),
Quicknav::Get { location, search } => commands::get(location, search),
Quicknav::List { shortcut } => commands::list(shortcut),
Quicknav::Add {
call,
location,
name,
description,
} => return commands::add(call, location, name, description),
} => commands::add(call, location, name, description),
Quicknav::Edit {
shortcut,
location,
name,
description,
} => return commands::edit(shortcut, location, name, description),
Quicknav::AddCall { shortcut, call } => return commands::add_call(shortcut, call),
Quicknav::Remove { shortcut } => return commands::remove(shortcut),
Quicknav::RemoveCall { call } => return commands::remove_call(call),
Quicknav::Config { option, new_value } => return commands::config(option, new_value),
Quicknav::Init { shell, command } => return commands::init(shell, command),
} => commands::edit(shortcut, location, name, description),
Quicknav::AddCall { shortcut, call } => commands::add_call(shortcut, call),
Quicknav::Remove { shortcut } => commands::remove(shortcut),
Quicknav::RemoveCall { call } => commands::remove_call(call),
Quicknav::Config { option, new_value } => commands::config(option, new_value),
Quicknav::Init { shell, command } => commands::init(shell, command),
},
Err(e) => {
if e.kind == ErrorKind::VersionDisplayed {
println!("");
println!();
return Ok(0);
}

return Err(anyhow!(e));
Err(anyhow!(e))
}
}
}
4 changes: 2 additions & 2 deletions src/utils/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use anyhow::{anyhow, Result};

pub fn to_bool(string: &str) -> Result<bool> {
match string.to_lowercase().as_str() {
"true" => return Ok(true),
"false" => return Ok(false),
"true" => Ok(true),
"false" => Ok(false),
_ => {
return Err(anyhow!(format!(
"The argument {} is not of type bool. The value must be true or false.",
Expand Down

0 comments on commit a982edd

Please sign in to comment.