Browse Source

Merge pull request #171 from praveenperera/clippy

Fix clippy warnings
pull/178/head
Andrew Cantino 5 months ago
committed by GitHub
parent
commit
36f8a0057d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/history/history.rs
  2. 6
      src/history/schema.rs
  3. 18
      src/history_cleaner.rs
  4. 13
      src/shell_history.rs
  5. 6
      src/training_cache.rs

6
src/history/history.rs

@ -619,10 +619,8 @@ impl History {
.unwrap_or_else(|err| panic!("McFly error: Query Map to work ({})", err));
let mut vec = Vec::new();
for result in command_iter {
if let Ok(command) = result {
vec.push(command);
}
for command in command_iter.flatten() {
vec.push(command);
}
vec

6
src/history/schema.rs

@ -127,10 +127,8 @@ fn cmd_strings(connection: &Connection) -> Vec<(i64, String)> {
.unwrap_or_else(|err| panic!("McFly error: Query Map to work ({})", err));
let mut vec = Vec::new();
for result in command_iter {
if let Ok(command) = result {
vec.push(command);
}
for command in command_iter.flatten() {
vec.push(command);
}
vec

18
src/history_cleaner.rs

@ -3,7 +3,7 @@ use crate::settings::{HistoryFormat, Settings};
use crate::shell_history;
use std::env;
use std::fs;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
pub fn clean(settings: &Settings, history: &History, command: &str) {
// Clean up the database.
@ -29,8 +29,8 @@ pub fn clean(settings: &Settings, history: &History, command: &str) {
}
}
fn clean_temporary_files(mcfly_history: &PathBuf, history_format: HistoryFormat, command: &str) {
let path = mcfly_history.as_path();
fn clean_temporary_files(mcfly_history: &Path, history_format: HistoryFormat, command: &str) {
let path = mcfly_history;
if let Some(directory) = path.parent() {
let expanded_path = fs::canonicalize(directory).unwrap_or_else(|err| {
panic!(
@ -40,13 +40,11 @@ fn clean_temporary_files(mcfly_history: &PathBuf, history_format: HistoryFormat,
});
let paths = fs::read_dir(&expanded_path).unwrap();
for path in paths {
if let Ok(entry) = path {
if let Some(file_name) = entry.path().file_name() {
if let Some(valid_unicode_str) = file_name.to_str() {
if valid_unicode_str.starts_with("mcfly.") {
shell_history::delete_lines(&entry.path(), history_format, command);
}
for entry in paths.flatten() {
if let Some(file_name) = entry.path().file_name() {
if let Some(valid_unicode_str) = file_name.to_str() {
if valid_unicode_str.starts_with("mcfly.") {
shell_history::delete_lines(&entry.path(), history_format, command);
}
}
}

13
src/shell_history.rs

@ -7,11 +7,12 @@ use std::fs::File;
use std::fs::OpenOptions;
use std::io::Read;
use std::io::Write;
use std::path::Path;
use std::path::PathBuf;
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};
fn read_ignoring_utf_errors(path: &PathBuf) -> String {
fn read_ignoring_utf_errors(path: &Path) -> String {
let mut f =
File::open(path).unwrap_or_else(|_| panic!("McFly error: {:?} file not found", &path));
let mut buffer = Vec::new();
@ -92,7 +93,7 @@ impl fmt::Display for HistoryCommand {
}
}
pub fn full_history(path: &PathBuf, history_format: HistoryFormat) -> Vec<HistoryCommand> {
pub fn full_history(path: &Path, history_format: HistoryFormat) -> Vec<HistoryCommand> {
match history_format {
HistoryFormat::Bash | HistoryFormat::Zsh { .. } => {
let history_contents = read_ignoring_utf_errors(path);
@ -139,7 +140,7 @@ pub fn full_history(path: &PathBuf, history_format: HistoryFormat) -> Vec<Histor
}
}
pub fn last_history_line(path: &PathBuf, history_format: HistoryFormat) -> Option<String> {
pub fn last_history_line(path: &Path, history_format: HistoryFormat) -> Option<String> {
// Could switch to https://github.com/mikeycgto/rev_lines
full_history(path, history_format)
.last()
@ -147,7 +148,7 @@ pub fn last_history_line(path: &PathBuf, history_format: HistoryFormat) -> Optio
}
pub fn delete_last_history_entry_if_search(
path: &PathBuf,
path: &Path,
history_format: HistoryFormat,
debug: bool,
) {
@ -188,7 +189,7 @@ pub fn delete_last_history_entry_if_search(
.unwrap_or_else(|_| panic!("McFly error: Unable to update {:?}", &path));
}
pub fn delete_lines(path: &PathBuf, history_format: HistoryFormat, command: &str) {
pub fn delete_lines(path: &Path, history_format: HistoryFormat, command: &str) {
let commands = full_history(path, history_format);
let zsh_timestamp_and_duration_regex = Regex::new(r"^: \d+:\d+;").unwrap();
@ -205,7 +206,7 @@ pub fn delete_lines(path: &PathBuf, history_format: HistoryFormat, command: &str
.unwrap_or_else(|_| panic!("McFly error: Unable to update {:?}", &path));
}
pub fn append_history_entry(command: &HistoryCommand, path: &PathBuf, debug: bool) {
pub fn append_history_entry(command: &HistoryCommand, path: &Path, debug: bool) {
let mut file = OpenOptions::new()
.write(true)
.append(true)

6
src/training_cache.rs

@ -2,9 +2,9 @@ use crate::history::Features;
use csv::Reader;
use csv::Writer;
use std::fs::File;
use std::path::PathBuf;
use std::path::Path;
pub fn write(data_set: &[(Features, bool)], cache_path: &PathBuf) {
pub fn write(data_set: &[(Features, bool)], cache_path: &Path) {
let mut writer = Writer::from_path(cache_path)
.unwrap_or_else(|err| panic!("McFly error: Expected to be able to write a CSV ({})", err));
output_header(&mut writer);
@ -14,7 +14,7 @@ pub fn write(data_set: &[(Features, bool)], cache_path: &PathBuf) {
}
}
pub fn read(cache_path: &PathBuf) -> Vec<(Features, bool)> {
pub fn read(cache_path: &Path) -> Vec<(Features, bool)> {
let mut data_set: Vec<(Features, bool)> = Vec::new();
let mut reader = Reader::from_path(cache_path).unwrap_or_else(|err| {

Loading…
Cancel
Save