@@ -18,39 +18,51 @@ fn main() -> anyhow::Result<()> {
1818
1919 let git_tree = FlattenGitTree :: init ( & client) . ok_or ( anyhow ! ( "Failed to init project list." ) ) ?;
2020
21- match git_tree. get ( & args. project ) {
22- Some ( element) => {
23- let content = element
24- . download ( & client)
25- . ok_or ( anyhow ! ( "Failed to download gitignore." ) ) ?;
21+ if args. list {
22+ git_tree
23+ . iter ( )
24+ . filter ( |e| {
25+ e. project
26+ . to_lowercase ( )
27+ . starts_with ( & args. project . to_lowercase ( ) )
28+ } )
29+ . for_each ( |e| println ! ( "- {}" , e. project) )
30+ } else {
31+ match git_tree. get ( & args. project ) {
32+ Some ( element) => {
33+ let content = element
34+ . download ( & client)
35+ . ok_or ( anyhow ! ( "Failed to download gitignore." ) ) ?;
2636
27- let file_path = args. path . as_path ( ) . join ( ".gitignore" ) ;
37+ let file_path = args. path . as_path ( ) . join ( ".gitignore" ) ;
2838
29- if file_path. exists ( ) {
30- // ask user to overwrite
31- println ! ( "File already exists. Overwrite? [y/n]" ) ;
39+ if file_path. exists ( ) {
40+ // ask user to overwrite
41+ println ! ( "File already exists. Overwrite? [y/n]" ) ;
3242
33- let mut input = String :: new ( ) ;
34- io:: stdin ( ) . read_line ( & mut input) ?;
43+ let mut input = String :: new ( ) ;
44+ io:: stdin ( ) . read_line ( & mut input) ?;
3545
36- if input. to_lowercase ( ) . trim ( ) != "y" {
37- return Ok ( ( ) ) ;
46+ if input. to_lowercase ( ) . trim ( ) != "y" {
47+ return Ok ( ( ) ) ;
48+ }
3849 }
39- }
4050
41- fs:: write ( file_path, content) . map_err ( |e| anyhow ! ( "Failed to write file: {}" , e) ) ?;
51+ fs:: write ( file_path, content)
52+ . map_err ( |e| anyhow ! ( "Failed to write file: {}" , e) ) ?;
4253
43- println ! ( "Successfully created .gitignore for {}" , args. project) ;
44- }
45- None => {
46- let suggest_keywords = git_tree. suggest_keywords ( & args. project ) ;
47- println ! (
48- "No project found for \" {}\" . Did you mean one of these?" ,
49- args. project
50- ) ;
51-
52- for keyword in suggest_keywords {
53- println ! ( "- {}" , keyword) ;
54+ println ! ( "Successfully created .gitignore for {}" , args. project) ;
55+ }
56+ None => {
57+ let suggest_keywords = git_tree. suggest_keywords ( & args. project ) ;
58+ println ! (
59+ "No project found for \" {}\" . Did you mean one of these?" ,
60+ args. project
61+ ) ;
62+
63+ for keyword in suggest_keywords {
64+ println ! ( "- {}" , keyword) ;
65+ }
5466 }
5567 }
5668 }
0 commit comments