extern crate clap;
extern crate memmap2;
use self::clap::Subcommand;
use serde::Serialize;
#[derive(Subcommand)]
pub enum Command {
Histogram {
filepath: String,
#[clap(long)]
json: bool,
},
Duplication {
paths: Vec<String>,
#[clap(long, default_value = "3")]
min_lines: usize,
#[clap(long)]
files_only: bool,
#[clap(long)]
json: bool,
},
LineLength {
paths: Vec<String>,
#[clap(long)]
json: bool,
},
}
pub struct Config {
pub command: Command,
}
#[derive(Debug)]
pub struct FileEntry {
pub name: String,
pub content: MappedContent,
}
#[derive(Debug)]
pub enum MappedContent {
Mapped(memmap2::Mmap),
String(String),
}
impl MappedContent {
pub fn as_str(&self) -> Option<&str> {
match self {
MappedContent::Mapped(mmap) => std::str::from_utf8(mmap).ok(),
MappedContent::String(s) => Some(s),
}
}
pub fn to_string(&self) -> Option<String> {
self.as_str().map(String::from)
}
}
impl PartialEq<str> for MappedContent {
fn eq(&self, other: &str) -> bool {
match self.as_str() {
Some(s) => s == other,
None => false,
}
}
}
impl PartialEq<&str> for MappedContent {
fn eq(&self, other: &&str) -> bool {
match self.as_str() {
Some(s) => s == *other,
None => false,
}
}
}
impl PartialEq<String> for MappedContent {
fn eq(&self, other: &String) -> bool {
match self.as_str() {
Some(s) => s == other,
None => false,
}
}
}
#[derive(PartialEq, Debug)]
pub struct LineEntry {
pub file_name: String,
pub line_number: u32,
pub content: String,
}
#[derive(Serialize)]
pub struct FrequencyItem {
pub word: String,
pub count: i32,
}
#[derive(Serialize)]
pub struct LineLengthItem {
pub length: usize,
pub count: usize,
}
#[derive(Serialize)]
pub struct DuplicationLocation {
pub path: String,
pub line: u32,
}
#[derive(Serialize)]
pub struct DuplicationItem {
pub content: String,
pub locations: Vec<DuplicationLocation>,
}