@@ -3,12 +3,15 @@ use crate::{
33 core:: { naughty_word, split_into_clean_words} ,
44} ;
55use git2:: { Commit , Repository } ;
6+ #[ cfg( feature = "json" ) ]
67use serde:: Serialize ;
78use std:: { collections:: HashMap , env, error:: Error , io, io:: Write , path:: Path } ;
9+ #[ cfg( feature = "table" ) ]
810use tabwriter:: TabWriter ;
911
1012/// A simple representation of a git repository.
11- #[ derive( Debug , Serialize ) ]
13+ #[ derive( Debug ) ]
14+ #[ cfg_attr( feature = "json" , derive( Serialize ) ) ]
1215pub struct Repo {
1316 /// Name of the repository.
1417 pub name : String ,
@@ -77,6 +80,7 @@ impl Repo {
7780 }
7881
7982 /// Serialize the `Repo` struct into a JSON-object and print it.
83+ #[ cfg( feature = "json" ) ]
8084 pub fn print_json ( & self ) -> Result < ( ) , Box < dyn Error > > {
8185 let serialized = serde_json:: to_string ( & self ) ?;
8286 write ! ( io:: stdout( ) , "{}" , serialized) ?;
@@ -86,6 +90,7 @@ impl Repo {
8690 }
8791
8892 /// Build a table to display naughty authors and their words.
93+ #[ cfg( feature = "table" ) ]
8994 pub fn print_list ( & self ) -> Result < ( ) , Box < dyn Error > > {
9095 let mut tw = TabWriter :: new ( vec ! [ ] ) ;
9196 let curses = Repo :: sort ( & self . curses ) ;
@@ -108,6 +113,7 @@ impl Repo {
108113 }
109114
110115 /// Create a sorted `Vec` from a HashMap of curses, sorted by counts
116+ #[ cfg( feature = "table" ) ]
111117 fn sort ( curses : & HashMap < String , usize > ) -> Vec < ( String , usize ) > {
112118 let mut curses: Vec < ( & String , & usize ) > = curses. iter ( ) . collect ( ) ;
113119 curses. sort_by ( |( a, _) , ( b, _) | a. cmp ( b) ) ;
@@ -119,6 +125,7 @@ impl Repo {
119125 }
120126
121127 /// Add headers to a table
128+ #[ cfg( feature = "table" ) ]
122129 fn table_headers (
123130 & self ,
124131 tw : & mut TabWriter < Vec < u8 > > ,
@@ -140,6 +147,7 @@ impl Repo {
140147 }
141148
142149 /// Add separators (`----`) to a table based on word lengths.
150+ #[ cfg( feature = "table" ) ]
143151 fn table_separators (
144152 & self ,
145153 tw : & mut TabWriter < Vec < u8 > > ,
@@ -160,6 +168,7 @@ impl Repo {
160168 }
161169
162170 /// Add all the naughty authors to the table.
171+ #[ cfg( feature = "table" ) ]
163172 fn table_authors (
164173 & self ,
165174 tw : & mut TabWriter < Vec < u8 > > ,
@@ -191,6 +200,7 @@ impl Repo {
191200 }
192201
193202 /// Sum up the total naughty count and print it.
203+ #[ cfg( feature = "table" ) ]
194204 fn table_total (
195205 & self ,
196206 tw : & mut TabWriter < Vec < u8 > > ,
0 commit comments