Skip to content

Commit e2ce768

Browse files
committed
Format code
1 parent 35d1a09 commit e2ce768

File tree

5 files changed

+98
-95
lines changed

5 files changed

+98
-95
lines changed

src/cli.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ pub enum RodoCommands {
1414
Catalog { opt_filepath: Option<String> },
1515
/// List all the TODOs in a given folder. The default value is the current directory.
1616
List { opt_filepath: Option<String> },
17-
1817
}

src/commands/list.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
extern crate walkdir;
2-
use walkdir::{DirEntry, WalkDir};
32
use std::fs::File;
4-
use std::io::{ self, Read};
3+
use std::io::{self, Read};
54
use std::str;
5+
use walkdir::{DirEntry, WalkDir};
66

7-
use super::parser::{Todo, parse_file};
7+
use super::parser::{parse_file, Todo};
88

99
fn is_hidden(entry: &DirEntry) -> bool {
10-
entry.file_name()
10+
entry
11+
.file_name()
1112
.to_str()
1213
.map(|s| s.starts_with('.'))
1314
.unwrap_or(false)
@@ -20,20 +21,19 @@ pub fn list_path_todos(directory_path: &str) -> Vec<Todo> {
2021
for file_path in WalkDir::new(directory_path)
2122
.into_iter()
2223
.filter_entry(|e| !is_hidden(e))
23-
.filter_map(|file| file.ok()) {
24-
25-
let file = File::open(file_path.path()).unwrap();
26-
let mut file_buffer = io::BufReader::new(file);
27-
let mut content_buffer = String::new();
24+
.filter_map(|file| file.ok())
25+
{
26+
let file = File::open(file_path.path()).unwrap();
27+
let mut file_buffer = io::BufReader::new(file);
28+
let mut content_buffer = String::new();
2829

29-
// file doesn't contain valid string (binary file): skip
30-
file_buffer
31-
.read_to_string(&mut content_buffer).ok();
30+
// file doesn't contain valid string (binary file): skip
31+
file_buffer.read_to_string(&mut content_buffer).ok();
3232

33-
// look for todos in file
34-
let mut file_todos = parse_file(content_buffer.as_str());
33+
// look for todos in file
34+
let mut file_todos = parse_file(content_buffer.as_str());
3535

36-
todos.append(&mut file_todos)
37-
}
36+
todos.append(&mut file_todos)
37+
}
3838
todos
3939
}

src/commands/parser.rs

+72-65
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use nom::{
2-
bytes::complete::{take_until, tag},
2+
bytes::complete::{tag, take_until},
33
character::complete::{newline, not_line_ending},
44
combinator::opt,
55
multi::many0,
@@ -22,14 +22,17 @@ fn parse_todo<'a>(todo_tag: &'a str, input: &'a str) -> IResult<&'a str, Todo> {
2222
// discard optional line ending
2323
let (input, _) = opt(newline)(input)?;
2424

25-
Ok((input, Todo {
26-
tag: todo_tag.to_owned(),
27-
text: text.to_owned(),
28-
}))
25+
Ok((
26+
input,
27+
Todo {
28+
tag: todo_tag.to_owned(),
29+
text: text.to_owned(),
30+
},
31+
))
2932
}
3033

3134
fn parse_todos(file_content: &str) -> IResult<&str, Vec<Todo>> {
32-
let line_parser = | file_content | parse_todo("TODO:", file_content);
35+
let line_parser = |file_content| parse_todo("TODO:", file_content);
3336
let (input, todos) = many0(line_parser)(file_content)?;
3437
Ok((input, todos))
3538
}
@@ -41,86 +44,85 @@ pub fn parse_file(file_content: &str) -> Vec<Todo> {
4144
}
4245
}
4346

44-
4547
#[cfg(test)]
4648
mod test {
47-
use crate::commands::parser::{parse_todos, Todo, parse_todo};
49+
use crate::commands::parser::{parse_todo, parse_todos, Todo};
4850

4951
#[test]
5052
fn todos() {
51-
let input =
52-
"line 1\n\
53+
let input = "line 1\n\
5354
TODO: todo1\n\
5455
line 2\n\
5556
line 3 -- TODO: todo2\n";
5657

57-
assert_eq!(parse_todos(input),
58-
Ok(("",
59-
vec![
60-
Todo{ tag: "TODO:".to_owned(),
61-
text: " todo1".to_owned()},
62-
Todo{ tag: "TODO:".to_owned(),
63-
text: " todo2".to_owned()},
64-
])
65-
)
58+
assert_eq!(
59+
parse_todos(input),
60+
Ok((
61+
"",
62+
vec![
63+
Todo {
64+
tag: "TODO:".to_owned(),
65+
text: " todo1".to_owned()
66+
},
67+
Todo {
68+
tag: "TODO:".to_owned(),
69+
text: " todo2".to_owned()
70+
},
71+
]
72+
))
6673
);
6774

6875
let input = "line 1\n";
69-
assert_eq!(parse_todos(input),
70-
Ok(("line 1\n",
71-
vec![])
72-
)
73-
);
76+
assert_eq!(parse_todos(input), Ok(("line 1\n", vec![])));
7477

7578
let input = "line1 TODO: todo1\n";
76-
assert_eq!(parse_todos(input),
77-
Ok(("",
78-
vec![
79-
Todo { tag: "TODO:".to_owned(),
80-
text: " todo1".to_owned()}])
81-
)
79+
assert_eq!(
80+
parse_todos(input),
81+
Ok((
82+
"",
83+
vec![Todo {
84+
tag: "TODO:".to_owned(),
85+
text: " todo1".to_owned()
86+
}]
87+
))
8288
);
8389

84-
let input =
85-
"line1\n\
90+
let input = "line1\n\
8691
line2\n\
8792
line3\n\
8893
TODO: todo1\n\
8994
line4\n";
90-
assert_eq!(parse_todos(input),
91-
Ok(("line4\n",
92-
vec![
93-
Todo { tag: "TODO:".to_owned(),
94-
text: " todo1".to_owned()}])
95-
)
95+
assert_eq!(
96+
parse_todos(input),
97+
Ok((
98+
"line4\n",
99+
vec![Todo {
100+
tag: "TODO:".to_owned(),
101+
text: " todo1".to_owned()
102+
}]
103+
))
96104
);
97105

98-
let input =
99-
"line1\n\
106+
let input = "line1\n\
100107
line2\n\
101108
line3\n\
102109
FIXME: todo1\n\
103110
line4\n";
104-
assert_eq!(parse_todos(input),
105-
Ok((input,
106-
vec![])
107-
)
108-
);
109-
111+
assert_eq!(parse_todos(input), Ok((input, vec![])));
110112
}
111113

112-
113114
#[test]
114115
fn todo_clean() {
115116
let input = "TODO: test todo";
116117
assert_eq!(
117118
parse_todo("TODO:", input),
118-
Ok(("",
119+
Ok((
120+
"",
119121
Todo {
120122
tag: "TODO:".to_owned(),
121123
text: " test todo".to_owned()
122-
})
123-
)
124+
}
125+
))
124126
);
125127
}
126128

@@ -129,34 +131,37 @@ mod test {
129131
let input = "TODO:\nline1";
130132
assert_eq!(
131133
parse_todo("TODO:", input),
132-
Ok(("line1",
134+
Ok((
135+
"line1",
133136
Todo {
134137
tag: "TODO:".to_owned(),
135138
text: "".to_owned()
136-
})
137-
)
139+
}
140+
))
138141
);
139142

140143
let input = "TODO:";
141144
assert_eq!(
142145
parse_todo("TODO:", input),
143-
Ok(("",
146+
Ok((
147+
"",
144148
Todo {
145149
tag: "TODO:".to_owned(),
146150
text: "".to_owned()
147-
})
148-
)
151+
}
152+
))
149153
);
150154

151155
let input = "TODO:\n";
152156
assert_eq!(
153157
parse_todo("TODO:", input),
154-
Ok(("",
158+
Ok((
159+
"",
155160
Todo {
156161
tag: "TODO:".to_owned(),
157162
text: "".to_owned()
158-
})
159-
)
163+
}
164+
))
160165
);
161166
}
162167

@@ -165,12 +170,13 @@ mod test {
165170
let input = "TODO: test todo\nline1";
166171
assert_eq!(
167172
parse_todo("TODO:", input),
168-
Ok(("line1",
173+
Ok((
174+
"line1",
169175
Todo {
170176
tag: "TODO:".to_owned(),
171177
text: " test todo".to_owned()
172-
})
173-
)
178+
}
179+
))
174180
);
175181
}
176182

@@ -179,12 +185,13 @@ mod test {
179185
let input = "// TODO: test todo";
180186
assert_eq!(
181187
parse_todo("TODO:", input),
182-
Ok(("",
188+
Ok((
189+
"",
183190
Todo {
184191
tag: "TODO:".to_owned(),
185192
text: " test todo".to_owned()
186-
})
187-
)
193+
}
194+
))
188195
);
189196
}
190197

src/display.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ use crate::commands::parser::Todo;
44

55
impl Todo {
66
pub fn display(todo: Todo) -> String {
7-
format!(
8-
"{} {}",
9-
todo.tag.bold().blue().underline(),
10-
todo.text)
7+
format!("{} {}", todo.tag.bold().blue().underline(), todo.text)
118
}
129
}
1310

1411
pub fn display_todos(todos: Vec<Todo>) {
1512
for todo in todos {
16-
println!("{}", Todo::display(todo));
13+
println!("{}", Todo::display(todo));
1714
}
1815
}

src/main.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod cli;
2+
use clap::Parser;
23
use cli::Cli;
34
use cli::RodoCommands;
4-
use clap::{Parser};
55
mod commands;
66
use commands::catalog;
77
use commands::list;
@@ -15,13 +15,13 @@ fn main() {
1515
let current_dir_str = current_dir.into_os_string().into_string().unwrap();
1616
match &cli.command {
1717
RodoCommands::Catalog { opt_filepath } => {
18-
let filepath = opt_filepath.to_owned().unwrap_or(current_dir_str);
19-
let _todos = catalog::catalog_path(filepath.as_str()).unwrap();
20-
},
21-
RodoCommands::List { opt_filepath } => {
22-
let filepath = opt_filepath.to_owned().unwrap_or(current_dir_str);
23-
let todos = list::list_path_todos(filepath.as_str());
24-
display_todos(todos)
18+
let filepath = opt_filepath.to_owned().unwrap_or(current_dir_str);
19+
let _todos = catalog::catalog_path(filepath.as_str()).unwrap();
20+
}
21+
RodoCommands::List { opt_filepath } => {
22+
let filepath = opt_filepath.to_owned().unwrap_or(current_dir_str);
23+
let todos = list::list_path_todos(filepath.as_str());
24+
display_todos(todos)
2525
}
2626
}
2727
}

0 commit comments

Comments
 (0)