style: code style
This commit is contained in:
41
src/main.rs
41
src/main.rs
@@ -1,35 +1,23 @@
|
|||||||
extern crate string_format;
|
|
||||||
extern crate clap;
|
|
||||||
extern crate walkdir;
|
|
||||||
extern crate string_parser;
|
|
||||||
extern crate dirs;
|
|
||||||
extern crate glob;
|
|
||||||
extern crate chrono;
|
|
||||||
use glob::glob;
|
|
||||||
use colored::Colorize;
|
|
||||||
use clap::{Arg, App, SubCommand};
|
|
||||||
use chrono::NaiveDate;
|
|
||||||
|
|
||||||
//local files
|
|
||||||
mod parser;
|
|
||||||
mod regex;
|
|
||||||
mod token;
|
|
||||||
use crate::parser::*;
|
|
||||||
use crate::regex::regex_parser;
|
|
||||||
use crate::token::Token;
|
|
||||||
|
|
||||||
//std
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{ self, BufRead };
|
use std::io::{ self, BufRead };
|
||||||
|
use glob::glob;
|
||||||
|
use colored::Colorize;
|
||||||
|
use clap::{ Arg, App, SubCommand };
|
||||||
|
use chrono::NaiveDate;
|
||||||
|
|
||||||
|
mod parser;
|
||||||
|
mod regex;
|
||||||
|
mod token;
|
||||||
|
|
||||||
|
use crate::parser::*;
|
||||||
|
use crate::regex::regex_parser;
|
||||||
|
use crate::token::Token;
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
let matches = App::new("Cargo-todo")
|
let matches = App::new("Cargo-todo")
|
||||||
.author("Clément Guiton <clement.guiton.dev@gmail.com>")
|
.author("Clément Guiton <clement.guiton.dev@gmail.com>")
|
||||||
.about("cargo tool to find TODOs in your code")
|
.about("cargo tool to find TODOs in your code")
|
||||||
@@ -244,9 +232,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
for i in tokens{
|
for i in tokens{
|
||||||
if new_tokens.len() < lines {
|
if new_tokens.len() < lines {
|
||||||
&new_tokens.push(i.clone());
|
&new_tokens.push(i.clone());
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,7 +272,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
|
|
||||||
if matches.is_present("exclude") {
|
if matches.is_present("exclude") {
|
||||||
let excludes : Vec<&str> = matches.values_of("exclude").unwrap().collect();
|
let excludes : Vec<&str> = matches.values_of("exclude").unwrap().collect();
|
||||||
let mut new_tokens : Vec<Token> = Vec::new();
|
let mut new_tokens : Vec<Token> = vec![];
|
||||||
for i in tokens{
|
for i in tokens{
|
||||||
for y in 0..excludes.len() {
|
for y in 0..excludes.len() {
|
||||||
if i.keyword == String::from(excludes[y]) {
|
if i.keyword == String::from(excludes[y]) {
|
||||||
@@ -305,8 +291,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
for i in tokens {
|
for i in tokens {
|
||||||
i.inline();
|
i.inline();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
for i in tokens {
|
for i in tokens {
|
||||||
println!("{}", i);
|
println!("{}", i);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
extern crate string_parser;
|
|
||||||
use string_parser::string_parser_with_file;
|
use string_parser::string_parser_with_file;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,19 @@
|
|||||||
extern crate regex;
|
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{ self, BufRead };
|
use std::io::{ self, BufRead };
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use regex::{RegexSet};
|
use regex::{RegexSet};
|
||||||
use crate::token::*;
|
use crate::token::*;
|
||||||
|
|
||||||
// The output is wrapped in a Result to allow matching on errors
|
// The output is wrapped in a Result to allow matching on errors
|
||||||
// Returns an Iterator to the Reader of the lines of the file.
|
// Returns an Iterator to the Reader of the lines of the file.
|
||||||
fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
|
fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>> where P: AsRef<Path>, {
|
||||||
where P: AsRef<Path>, {
|
|
||||||
let file = File::open(filename)?;
|
let file = File::open(filename)?;
|
||||||
Ok(io::BufReader::new(file).lines())
|
Ok(io::BufReader::new(file).lines())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn regex_parser(path : &str, regex : Vec<String>, verbosity : i8) -> Result<Vec<Token>, io::Error> {
|
pub fn regex_parser(path : &str, regex : Vec<String>, verbosity : i8) -> Result<Vec<Token>, io::Error> {
|
||||||
|
|
||||||
let set = RegexSet::new(regex).unwrap();
|
let set = RegexSet::new(regex).unwrap();
|
||||||
let mut tokens = Vec::new();
|
let mut tokens = vec![];
|
||||||
let mut line_cpt = 0;
|
let mut line_cpt = 0;
|
||||||
for line in read_lines(path)? {
|
for line in read_lines(path)? {
|
||||||
line_cpt +=1;
|
line_cpt +=1;
|
||||||
|
|||||||
19
src/token.rs
19
src/token.rs
@@ -1,7 +1,3 @@
|
|||||||
extern crate string_format;
|
|
||||||
extern crate regex;
|
|
||||||
extern crate chrono;
|
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use string_format::string_format;
|
use string_format::string_format;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
@@ -48,16 +44,13 @@ impl Token {
|
|||||||
for i in 0..fields.len() {
|
for i in 0..fields.len() {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
t.keyword = fields[0].to_string().to_lowercase();
|
t.keyword = fields[0].to_string().to_lowercase();
|
||||||
}
|
} else if number_regex.is_match(fields[i]) {
|
||||||
else if number_regex.is_match(fields[i]) {
|
|
||||||
t.priority = Some(fields[i].to_string());
|
t.priority = Some(fields[i].to_string());
|
||||||
}
|
} else if date_regex.is_match(fields[i]) {
|
||||||
else if date_regex.is_match(fields[i]){
|
|
||||||
let date : Vec<&str> = fields[i].split("/").collect();
|
let date : Vec<&str> = fields[i].split("/").collect();
|
||||||
t.date = NaiveDate::from_ymd_opt(date[0].parse::<i32>().unwrap(), date[1].parse::<u32>().unwrap(), date[2].parse::<u32>().unwrap());
|
t.date = NaiveDate::from_ymd_opt(date[0].parse::<i32>().unwrap(), date[1].parse::<u32>().unwrap(), date[2].parse::<u32>().unwrap());
|
||||||
// t.date = Some(fields[i].to_string());
|
// t.date = Some(fields[i].to_string());
|
||||||
}
|
} else if member_regex.is_match(fields[i]) {
|
||||||
else if member_regex.is_match(fields[i]){
|
|
||||||
let mut member = String::new(); //from(fields[i].clone()).chars().next().map(|c| &s[c.len_utf8()..]).unwrap();
|
let mut member = String::new(); //from(fields[i].clone()).chars().next().map(|c| &s[c.len_utf8()..]).unwrap();
|
||||||
let it = fields[i].chars().skip(1);
|
let it = fields[i].chars().skip(1);
|
||||||
for i in it {
|
for i in it {
|
||||||
@@ -65,12 +58,10 @@ impl Token {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.member = Some(member);
|
t.member = Some(member);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if t.comment.is_none() {
|
if t.comment.is_none() {
|
||||||
t.comment = Some(fields[i].to_string());
|
t.comment = Some(fields[i].to_string());
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
t.comment = Some(string_format!("{} {}".to_string(),t.comment.unwrap(), fields[i].to_string()));
|
t.comment = Some(string_format!("{} {}".to_string(),t.comment.unwrap(), fields[i].to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user