From 3642f0112a6233e3d253c5e5ca247d8099c04d55 Mon Sep 17 00:00:00 2001 From: Lynne Date: Mon, 15 Feb 2021 02:20:48 +1000 Subject: [PATCH] version bump, minor cleanup, cli parse fix previously, `fif -e rs src` would be interpreted as "scan for files with extensions 'rs' and 'src' in the default directory" instead of "scan for files with extension 'rs' in 'src'" - this has been fixed --- Cargo.lock | 4 ++-- Cargo.toml | 7 +++++-- src/formats.rs | 13 +++++-------- src/main.rs | 32 +++++++++++++++++--------------- src/parameters.rs | 6 +++--- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1bf038..b55bef4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -169,7 +169,7 @@ dependencies = [ [[package]] name = "fif" -version = "0.1.0" +version = "0.2.0" dependencies = [ "cached", "clap", @@ -620,7 +620,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "xdg-mime" version = "0.3.3" -source = "git+https://github.com/ebassi/xdg-mime-rs#de5a6dd04b1a225894c51b5c6e5f5a22ffa46373" +source = "git+https://github.com/ebassi/xdg-mime-rs?rev=de5a6dd#de5a6dd04b1a225894c51b5c6e5f5a22ffa46373" dependencies = [ "dirs-next", "glob", diff --git a/Cargo.toml b/Cargo.toml index d6956b6..06efe0f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,12 @@ [package] name = "fif" -version = "0.1.0" +description = "A command-line tool for detecting and optionally correcting files with incorrect extensions." +version = "0.2.0" authors = ["Lynnesbian "] edition = "2018" license = "GPL-3.0-or-later" +rust-version = "1.43.0" # cached requires 1.42.0 +#resolver = "2" #license-file = "LICENSE" [features] @@ -16,7 +19,7 @@ walkdir = "2.3.1" log = "0.4.14" smartstring = "0.2.6" # use git version while waiting on a release incorporating https://github.com/ebassi/xdg-mime-rs/commit/de5a6dd -xdg-mime = {git = "https://github.com/ebassi/xdg-mime-rs", version = "0.3"} +xdg-mime = {git = "https://github.com/ebassi/xdg-mime-rs", version = "0.3", rev = "de5a6dd"} mime_guess = "2.0.3" rayon = "1.5.0" snailquote = "0.3.0" diff --git a/src/formats.rs b/src/formats.rs index 71c628b..cd4ed39 100644 --- a/src/formats.rs +++ b/src/formats.rs @@ -77,10 +77,7 @@ pub trait Format { pub struct Script {} impl Format for Script { - // TODO: begin write_all output with "#!/bin/sh" or w/e - fn new() -> Self { - return Script {} - } + fn new() -> Self { Self {} } fn rename(&self, f: &mut W, from: &PathBuf, to: &PathBuf) -> io::Result<()> { // TODO: surely there's a better way... @@ -88,25 +85,25 @@ impl Format for Script { write_pathbuf(f, from)?; write!(f, " ")?; write_pathbuf(f, to)?; - write!(f, "\n") + writeln!(f, ) } fn no_known_extension(&self, f: &mut W, path: &PathBuf) -> io::Result<()> { write!(f, "echo No known extension for ")?; write_pathbuf(f, path)?; - write!(f, "\n") + writeln!(f, ) } fn unreadable(&self, f: &mut W, path: &PathBuf) -> io::Result<()> { write!(f, "# Failed to read ")?; write_pathbuf(f, path)?; - write!(f, "\n") + writeln!(f, ) } fn unknown_type(&self, f: &mut W, path: &PathBuf) -> io::Result<()> { write!(f, "# Failed to detect mime type for ")?; write_pathbuf(f, path)?; - write!(f, "\n") + writeln!(f, ) } fn header(&self, _: &Entries, f: &mut W) -> io::Result<()> { diff --git a/src/main.rs b/src/main.rs index 7a2b183..9ea7747 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -// fif - File Info Fixer +// fif - a command-line tool for detecting and optionally correcting files with incorrect extensions. // Copyright (C) 2021 Lynnesbian // // This program is free software: you can redistribute it and/or modify @@ -14,25 +14,27 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +use std::fmt::{self, Display}; +use std::io::{BufWriter, stdout}; +use std::path::{Path, PathBuf}; + +use clap::Clap; +use log::{debug, info, trace, warn}; +use mime_guess::Mime; +use rayon::prelude::*; +use smartstring::alias::String; +use walkdir::{DirEntry, WalkDir}; +use xdg_mime::SharedMimeInfo; + +use crate::formats::{Format, Script}; +use crate::parameters::OutputFormat; +use crate::scanerror::ScanError; + mod parameters; mod inspectors; mod formats; mod scanerror; -use std::path::{Path, PathBuf}; -use walkdir::{WalkDir, DirEntry}; -use mime_guess::Mime; -use smartstring::alias::String; -use clap::Clap; -use log::{debug, trace, info, warn}; -use rayon::prelude::*; -use std::fmt::{self, Display}; -use xdg_mime::SharedMimeInfo; -use std::io::{stdout, BufWriter}; -use crate::parameters::OutputFormat; -use crate::scanerror::ScanError; -use crate::formats::{Script, Format}; - pub struct Findings { file: PathBuf, // TODO: replace with Path???? <'a> and all that valid: bool, diff --git a/src/parameters.rs b/src/parameters.rs index 8957db6..94c5424 100644 --- a/src/parameters.rs +++ b/src/parameters.rs @@ -1,5 +1,6 @@ -use clap::{Clap}; use std::path::PathBuf; + +use clap::Clap; use smartstring::{LazyCompact, SmartString}; #[derive(Clap, PartialEq, Debug)] @@ -11,7 +12,7 @@ pub enum OutputFormat { #[derive(Clap, Debug)] pub struct Parameters { /// Only examine files with these extensions (Comma-separated list) - #[clap(short, long, use_delimiter = true)] + #[clap(short, long, use_delimiter = true, require_delimiter = true)] pub extensions: Option>>, /// Don't skip hidden files and directories @@ -25,6 +26,5 @@ pub struct Parameters { /// Directory to process // TODO: right now this can only take a single directory - should this be improved? #[clap(name = "DIR", default_value = ".", parse(from_os_str))] - // dirs: PathBuf pub dirs: PathBuf, }