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]]
|
[[package]]
|
||||||
name = "fif"
|
name = "fif"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cached",
|
"cached",
|
||||||
"clap",
|
"clap",
|
||||||
|
@ -620,7 +620,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xdg-mime"
|
name = "xdg-mime"
|
||||||
version = "0.3.3"
|
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 = [
|
dependencies = [
|
||||||
"dirs-next",
|
"dirs-next",
|
||||||
"glob",
|
"glob",
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
[package]
|
[package]
|
||||||
name = "fif"
|
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>"]
|
authors = ["Lynnesbian <lynne@bune.city>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
|
rust-version = "1.43.0" # cached requires 1.42.0
|
||||||
|
#resolver = "2"
|
||||||
#license-file = "LICENSE"
|
#license-file = "LICENSE"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
@ -16,7 +19,7 @@ walkdir = "2.3.1"
|
||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
smartstring = "0.2.6"
|
smartstring = "0.2.6"
|
||||||
# use git version while waiting on a release incorporating https://github.com/ebassi/xdg-mime-rs/commit/de5a6dd
|
# 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"
|
mime_guess = "2.0.3"
|
||||||
rayon = "1.5.0"
|
rayon = "1.5.0"
|
||||||
snailquote = "0.3.0"
|
snailquote = "0.3.0"
|
||||||
|
|
|
@ -77,10 +77,7 @@ pub trait Format {
|
||||||
|
|
||||||
pub struct Script {}
|
pub struct Script {}
|
||||||
impl Format for Script {
|
impl Format for Script {
|
||||||
// TODO: begin write_all output with "#!/bin/sh" or w/e
|
fn new() -> Self { Self {} }
|
||||||
fn new() -> Self {
|
|
||||||
return Script {}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rename<W: Write>(&self, f: &mut W, from: &PathBuf, to: &PathBuf) -> io::Result<()> {
|
fn rename<W: Write>(&self, f: &mut W, from: &PathBuf, to: &PathBuf) -> io::Result<()> {
|
||||||
// TODO: surely there's a better way...
|
// TODO: surely there's a better way...
|
||||||
|
@ -88,25 +85,25 @@ impl Format for Script {
|
||||||
write_pathbuf(f, from)?;
|
write_pathbuf(f, from)?;
|
||||||
write!(f, " ")?;
|
write!(f, " ")?;
|
||||||
write_pathbuf(f, to)?;
|
write_pathbuf(f, to)?;
|
||||||
write!(f, "\n")
|
writeln!(f, )
|
||||||
}
|
}
|
||||||
|
|
||||||
fn no_known_extension<W: Write>(&self, f: &mut W, path: &PathBuf) -> io::Result<()> {
|
fn no_known_extension<W: Write>(&self, f: &mut W, path: &PathBuf) -> io::Result<()> {
|
||||||
write!(f, "echo No known extension for ")?;
|
write!(f, "echo No known extension for ")?;
|
||||||
write_pathbuf(f, path)?;
|
write_pathbuf(f, path)?;
|
||||||
write!(f, "\n")
|
writeln!(f, )
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unreadable<W: Write>(&self, f: &mut W, path: &PathBuf) -> io::Result<()> {
|
fn unreadable<W: Write>(&self, f: &mut W, path: &PathBuf) -> io::Result<()> {
|
||||||
write!(f, "# Failed to read ")?;
|
write!(f, "# Failed to read ")?;
|
||||||
write_pathbuf(f, path)?;
|
write_pathbuf(f, path)?;
|
||||||
write!(f, "\n")
|
writeln!(f, )
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unknown_type<W: Write>(&self, f: &mut W, path: &PathBuf) -> io::Result<()> {
|
fn unknown_type<W: Write>(&self, f: &mut W, path: &PathBuf) -> io::Result<()> {
|
||||||
write!(f, "# Failed to detect mime type for ")?;
|
write!(f, "# Failed to detect mime type for ")?;
|
||||||
write_pathbuf(f, path)?;
|
write_pathbuf(f, path)?;
|
||||||
write!(f, "\n")
|
writeln!(f, )
|
||||||
}
|
}
|
||||||
|
|
||||||
fn header<W: Write>(&self, _: &Entries, f: &mut W) -> io::Result<()> {
|
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
|
// Copyright (C) 2021 Lynnesbian
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// 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
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// 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 parameters;
|
||||||
mod inspectors;
|
mod inspectors;
|
||||||
mod formats;
|
mod formats;
|
||||||
mod scanerror;
|
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 {
|
pub struct Findings {
|
||||||
file: PathBuf, // TODO: replace with Path???? <'a> and all that
|
file: PathBuf, // TODO: replace with Path???? <'a> and all that
|
||||||
valid: bool,
|
valid: bool,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use clap::{Clap};
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use clap::Clap;
|
||||||
use smartstring::{LazyCompact, SmartString};
|
use smartstring::{LazyCompact, SmartString};
|
||||||
|
|
||||||
#[derive(Clap, PartialEq, Debug)]
|
#[derive(Clap, PartialEq, Debug)]
|
||||||
|
@ -11,7 +12,7 @@ pub enum OutputFormat {
|
||||||
#[derive(Clap, Debug)]
|
#[derive(Clap, Debug)]
|
||||||
pub struct Parameters {
|
pub struct Parameters {
|
||||||
/// Only examine files with these extensions (Comma-separated list)
|
/// 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>>>,
|
pub extensions: Option<Vec<SmartString<LazyCompact>>>,
|
||||||
|
|
||||||
/// Don't skip hidden files and directories
|
/// Don't skip hidden files and directories
|
||||||
|
@ -25,6 +26,5 @@ pub struct Parameters {
|
||||||
/// Directory to process
|
/// Directory to process
|
||||||
// TODO: right now this can only take a single directory - should this be improved?
|
// TODO: right now this can only take a single directory - should this be improved?
|
||||||
#[clap(name = "DIR", default_value = ".", parse(from_os_str))]
|
#[clap(name = "DIR", default_value = ".", parse(from_os_str))]
|
||||||
// dirs: PathBuf
|
|
||||||
pub dirs: PathBuf,
|
pub dirs: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue