style: code style

This commit is contained in:
2020-07-26 14:43:19 +08:00
parent af156e7f7c
commit be41947f42
4 changed files with 86 additions and 116 deletions

View File

@@ -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::fs::OpenOptions;
use std::env;
use std::path::Path;
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<()> {
let matches = App::new("Cargo-todo")
.author("Clément Guiton <clement.guiton.dev@gmail.com>")
.about("cargo tool to find TODOs in your code")
@@ -169,7 +157,7 @@ fn main() -> std::io::Result<()> {
let path = entry.unwrap();
let path = Path::new(&path).strip_prefix(env::current_dir().unwrap().to_str().unwrap()).unwrap();
// println!("{}", path.to_str().unwrap());
if !path.starts_with("target/"){
if !path.starts_with("target/") {
let path = path.to_str().unwrap();
if matches.occurrences_of("verbose") == 0 || matches.occurrences_of("verbose") == 2{
@@ -181,7 +169,7 @@ fn main() -> std::io::Result<()> {
}
}
else {
match regex_parser(path, regex.clone(), 1){
match regex_parser(path, regex.clone(), 1) {
Ok(mut t) => {
tokens.append(&mut t);
},
@@ -193,8 +181,8 @@ fn main() -> std::io::Result<()> {
}
if matches.is_present("sort"){
if matches.value_of("sort").unwrap() == "priority"{
if matches.is_present("sort") {
if matches.value_of("sort").unwrap() == "priority" {
fn token_priority_sort(t : &Token) -> String {
if t.priority.is_none() {
@@ -206,7 +194,7 @@ fn main() -> std::io::Result<()> {
}
tokens.sort_unstable_by_key(token_priority_sort);
}
else if matches.value_of("sort").unwrap() == "deadline"{
else if matches.value_of("sort").unwrap() == "deadline" {
fn token_deadline_sort(t : &Token) -> NaiveDate {
if t.date.is_none() {
@@ -218,7 +206,7 @@ fn main() -> std::io::Result<()> {
}
tokens.sort_unstable_by_key(token_deadline_sort);
}
else if matches.value_of("sort").unwrap() == "member"{
else if matches.value_of("sort").unwrap() == "member" {
fn token_member_sort(t : &Token) -> String {
if t.priority.is_none() {
@@ -232,8 +220,8 @@ fn main() -> std::io::Result<()> {
}
}
if matches.is_present("list"){
let lines = match matches.value_of("list").unwrap().parse::<usize>(){
if matches.is_present("list") {
let lines = match matches.value_of("list").unwrap().parse::<usize>() {
Ok(lines) => lines,
Err(_) => {
eprintln!("{}", "list argument should be a valid number!".red());
@@ -242,18 +230,16 @@ fn main() -> std::io::Result<()> {
let mut new_tokens : Vec<Token> = Vec::new();
for i in tokens{
if new_tokens.len() < lines{
if new_tokens.len() < lines {
&new_tokens.push(i.clone());
}
else
{
} else {
break;
}
}
tokens = new_tokens;
}
if matches.is_present("member"){
if matches.is_present("member") {
let filters : Vec<&str> = matches.values_of("member").unwrap().collect();
let mut new_tokens : Vec<Token> = Vec::new();
for i in tokens{
@@ -269,10 +255,10 @@ fn main() -> std::io::Result<()> {
tokens = new_tokens;
}
if matches.is_present("filter"){
if matches.is_present("filter") {
let filters : Vec<&str> = matches.values_of("filter").unwrap().collect();
let mut new_tokens : Vec<Token> = Vec::new();
for i in tokens{
for i in tokens {
for y in &filters {
if i.keyword == String::from(*y){
&new_tokens.push(i.clone());
@@ -284,12 +270,12 @@ fn main() -> std::io::Result<()> {
// tokens = new.into_iter().filter(|t| t.keyword == String::from(matches.value_of("filter").unwrap())).collect();
}
if matches.is_present("exclude"){
if matches.is_present("exclude") {
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 y in 0..excludes.len() {
if i.keyword == String::from(excludes[y]){
if i.keyword == String::from(excludes[y]) {
break;
}
else if y == excludes.len() -1{
@@ -301,12 +287,11 @@ fn main() -> std::io::Result<()> {
tokens = new_tokens;
// tokens = new.into_iter().filter(|t| t.keyword == String::from(matches.value_of("filter").unwrap())).collect();
}
if matches.is_present("inline"){
for i in tokens{
if matches.is_present("inline") {
for i in tokens {
i.inline();
}
}
else {
} else {
for i in tokens {
println!("{}", i);
}