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
This commit is contained in:
parent
cda6184d45
commit
3642f0112a
5 changed files with 32 additions and 30 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -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",
|
||||
|
|
|
@ -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 <lynne@bune.city>"]
|
||||
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"
|
||||
|
|
|
@ -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<W: Write>(&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<W: Write>(&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<W: Write>(&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<W: Write>(&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<W: Write>(&self, _: &Entries, f: &mut W) -> io::Result<()> {
|
||||
|
|
32
src/main.rs
32
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
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,
|
||||
|
|
|
@ -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<Vec<SmartString<LazyCompact>>>,
|
||||
|
||||
/// 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,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue