@@ -11,6 +11,7 @@ use onefetch_image::ImageProtocol;
11
11
use onefetch_manifest:: ManifestType ;
12
12
use regex:: Regex ;
13
13
use serde:: Serialize ;
14
+ use merge:: Merge ;
14
15
use std:: env;
15
16
use std:: io;
16
17
use std:: path:: PathBuf ;
@@ -20,12 +21,18 @@ use strum::IntoEnumIterator;
20
21
const COLOR_RESOLUTIONS : [ & str ; 5 ] = [ "16" , "32" , "64" , "128" , "256" ] ;
21
22
pub const NO_BOTS_DEFAULT_REGEX_PATTERN : & str = r"(?:-|\s)[Bb]ot$|\[[Bb]ot\]" ;
22
23
23
- #[ derive( Clone , Debug , Parser , PartialEq , Eq ) ]
24
+ #[ derive( Clone , Debug , Parser , PartialEq , Eq , Merge ) ]
24
25
#[ command( version, about) ]
25
26
pub struct CliOptions {
26
27
/// Run as if onefetch was started in <input> instead of the current working directory
27
28
#[ arg( default_value = "." , hide_default_value = true , value_hint = ValueHint :: DirPath ) ]
29
+ #[ merge( skip) ]
28
30
pub input : PathBuf ,
31
+ /// Specify a custom path to a config file.
32
+ /// Default config is located at ${HOME}/.config/onefetch/config.conf.
33
+ #[ arg( long, value_hint = ValueHint :: AnyPath ) ]
34
+ #[ merge( skip) ]
35
+ pub config_path : Option < PathBuf > ,
29
36
#[ command( flatten) ]
30
37
pub info : InfoCliOptions ,
31
38
#[ command( flatten) ]
@@ -42,7 +49,7 @@ pub struct CliOptions {
42
49
pub other : OtherCliOptions ,
43
50
}
44
51
45
- #[ derive( Clone , Debug , Args , PartialEq , Eq ) ]
52
+ #[ derive( Clone , Debug , Args , PartialEq , Eq , Merge ) ]
46
53
#[ command( next_help_heading = "INFO" ) ]
47
54
pub struct InfoCliOptions {
48
55
/// Allows you to disable FIELD(s) from appearing in the output
@@ -54,27 +61,34 @@ pub struct InfoCliOptions {
54
61
value_enum,
55
62
value_name = "FIELD"
56
63
) ]
64
+ #[ merge( strategy = overwrite_vec) ]
57
65
pub disabled_fields : Vec < InfoType > ,
58
66
/// Hides the title
59
67
#[ arg( long) ]
68
+ #[ merge( strategy = merge:: bool :: overwrite_false) ]
60
69
pub no_title : bool ,
61
70
/// Maximum NUM of authors to be shown
62
71
#[ arg( long, default_value_t = 3usize , value_name = "NUM" ) ]
72
+ #[ merge( strategy = overwrite) ]
63
73
pub number_of_authors : usize ,
64
74
/// Maximum NUM of languages to be shown
65
75
#[ arg( long, default_value_t = 6usize , value_name = "NUM" ) ]
76
+ #[ merge( strategy = overwrite) ]
66
77
pub number_of_languages : usize ,
67
78
/// Maximum NUM of file churns to be shown
68
79
#[ arg( long, default_value_t = 3usize , value_name = "NUM" ) ]
80
+ #[ merge( strategy = overwrite) ]
69
81
pub number_of_file_churns : usize ,
70
82
/// Minimum NUM of commits from HEAD used to compute the churn summary
71
83
///
72
84
/// By default, the actual value is non-deterministic due to time-based computation
73
85
/// and will be displayed under the info title "Churn (NUM)"
74
86
#[ arg( long, value_name = "NUM" ) ]
87
+ #[ merge( strategy = overwrite) ]
75
88
pub churn_pool_size : Option < usize > ,
76
89
/// Ignore all files & directories matching EXCLUDE
77
90
#[ arg( long, short, num_args = 1 ..) ]
91
+ #[ merge( strategy = overwrite_vec) ]
78
92
pub exclude : Vec < String > ,
79
93
/// Exclude [bot] commits. Use <REGEX> to override the default pattern
80
94
#[ arg(
@@ -84,21 +98,27 @@ pub struct InfoCliOptions {
84
98
default_missing_value = NO_BOTS_DEFAULT_REGEX_PATTERN ,
85
99
value_name = "REGEX"
86
100
) ]
101
+ #[ merge( strategy = overwrite) ]
87
102
pub no_bots : Option < MyRegex > ,
88
103
/// Ignores merge commits
89
104
#[ arg( long) ]
105
+ #[ merge( strategy = merge:: bool :: overwrite_false) ]
90
106
pub no_merges : bool ,
91
107
/// Show the email address of each author
92
108
#[ arg( long, short = 'E' ) ]
109
+ #[ merge( strategy = merge:: bool :: overwrite_false) ]
93
110
pub email : bool ,
94
111
/// Display repository URL as HTTP
95
112
#[ arg( long) ]
113
+ #[ merge( strategy = merge:: bool :: overwrite_false) ]
96
114
pub http_url : bool ,
97
115
/// Hide token in repository URL
98
116
#[ arg( long) ]
117
+ #[ merge( strategy = merge:: bool :: overwrite_false) ]
99
118
pub hide_token : bool ,
100
119
/// Count hidden files and directories
101
120
#[ arg( long) ]
121
+ #[ merge( strategy = merge:: bool :: overwrite_false) ]
102
122
pub include_hidden : bool ,
103
123
/// Filters output by language type
104
124
#[ arg(
@@ -108,10 +128,11 @@ pub struct InfoCliOptions {
108
128
short = 'T' ,
109
129
value_enum,
110
130
) ]
131
+ #[ merge( strategy = overwrite_vec) ]
111
132
pub r#type : Vec < LanguageType > ,
112
133
}
113
134
114
- #[ derive( Clone , Debug , Args , PartialEq , Eq ) ]
135
+ #[ derive( Clone , Debug , Args , PartialEq , Eq , Merge ) ]
115
136
#[ command( next_help_heading = "ASCII" ) ]
116
137
pub struct AsciiCliOptions {
117
138
/// Takes a non-empty STRING as input to replace the ASCII logo
@@ -122,6 +143,7 @@ pub struct AsciiCliOptions {
122
143
///
123
144
/// '--ascii-input "$(fortune | cowsay -W 25)"'
124
145
#[ arg( long, value_name = "STRING" , value_hint = ValueHint :: CommandString ) ]
146
+ #[ merge( strategy = overwrite) ]
125
147
pub ascii_input : Option < String > ,
126
148
/// Colors (X X X...) to print the ascii art
127
149
#[ arg(
@@ -131,6 +153,7 @@ pub struct AsciiCliOptions {
131
153
short = 'c' ,
132
154
value_parser = value_parser!( u8 ) . range( ..16 ) ,
133
155
) ]
156
+ #[ merge( strategy = overwrite_vec) ]
134
157
pub ascii_colors : Vec < u8 > ,
135
158
/// Which LANGUAGE's ascii art to print
136
159
#[ arg(
@@ -140,22 +163,26 @@ pub struct AsciiCliOptions {
140
163
value_enum,
141
164
hide_possible_values = true
142
165
) ]
166
+ #[ merge( skip) ]
143
167
pub ascii_language : Option < Language > ,
144
168
/// Specify when to use true color
145
169
///
146
170
/// If set to auto: true color will be enabled if supported by the terminal
147
171
#[ arg( long, default_value = "auto" , value_name = "WHEN" , value_enum) ]
172
+ #[ merge( strategy = overwrite) ]
148
173
pub true_color : When ,
149
174
}
150
175
151
- #[ derive( Clone , Debug , Args , PartialEq , Eq ) ]
176
+ #[ derive( Clone , Debug , Args , PartialEq , Eq , Merge ) ]
152
177
#[ command( next_help_heading = "IMAGE" ) ]
153
178
pub struct ImageCliOptions {
154
179
/// Path to the IMAGE file
155
180
#[ arg( long, short, value_hint = ValueHint :: FilePath ) ]
181
+ #[ merge( strategy = overwrite) ]
156
182
pub image : Option < PathBuf > ,
157
183
/// Which image PROTOCOL to use
158
184
#[ arg( long, value_enum, requires = "image" , value_name = "PROTOCOL" ) ]
185
+ #[ merge( skip) ]
159
186
pub image_protocol : Option < ImageProtocol > ,
160
187
/// VALUE of color resolution to use with SIXEL backend
161
188
#[ arg(
@@ -166,10 +193,11 @@ pub struct ImageCliOptions {
166
193
value_parser = PossibleValuesParser :: new( COLOR_RESOLUTIONS )
167
194
. map( |s| s. parse:: <usize >( ) . unwrap( ) )
168
195
) ]
196
+ #[ merge( strategy = overwrite) ]
169
197
pub color_resolution : usize ,
170
198
}
171
199
172
- #[ derive( Clone , Debug , Args , PartialEq , Eq ) ]
200
+ #[ derive( Clone , Debug , Args , PartialEq , Eq , Merge ) ]
173
201
#[ command( next_help_heading = "TEXT FORMATTING" ) ]
174
202
pub struct TextForamttingCliOptions {
175
203
/// Changes the text colors (X X X...)
@@ -186,59 +214,71 @@ pub struct TextForamttingCliOptions {
186
214
value_parser = value_parser!( u8 ) . range( ..16 ) ,
187
215
num_args = 1 ..=6
188
216
) ]
217
+ #[ merge( strategy = overwrite_vec) ]
189
218
pub text_colors : Vec < u8 > ,
190
219
/// Use ISO 8601 formatted timestamps
191
220
#[ arg( long, short = 'z' ) ]
221
+ #[ merge( strategy = merge:: bool :: overwrite_false) ]
192
222
pub iso_time : bool ,
193
223
/// Which thousands SEPARATOR to use
194
224
#[ arg( long, value_name = "SEPARATOR" , default_value = "plain" , value_enum) ]
225
+ #[ merge( strategy = overwrite) ]
195
226
pub number_separator : NumberSeparator ,
196
227
/// Turns off bold formatting
197
228
#[ arg( long) ]
229
+ #[ merge( strategy = merge:: bool :: overwrite_false) ]
198
230
pub no_bold : bool ,
199
231
}
200
- #[ derive( Clone , Debug , Args , PartialEq , Eq , Default ) ]
232
+ #[ derive( Clone , Debug , Args , PartialEq , Eq , Default , Merge ) ]
201
233
#[ command( next_help_heading = "VISUALS" ) ]
202
234
pub struct VisualsCliOptions {
203
235
/// Hides the color palette
204
236
#[ arg( long) ]
237
+ #[ merge( strategy = merge:: bool :: overwrite_false) ]
205
238
pub no_color_palette : bool ,
206
239
/// Hides the ascii art or image if provided
207
240
#[ arg( long) ]
241
+ #[ merge( strategy = merge:: bool :: overwrite_false) ]
208
242
pub no_art : bool ,
209
243
/// Use Nerd Font icons
210
244
///
211
245
/// Replaces language chips with Nerd Font icons
212
246
#[ arg( long) ]
247
+ #[ merge( strategy = merge:: bool :: overwrite_false) ]
213
248
pub nerd_fonts : bool ,
214
249
}
215
250
216
- #[ derive( Clone , Debug , Args , PartialEq , Eq , Default ) ]
251
+ #[ derive( Clone , Debug , Args , PartialEq , Eq , Default , Merge ) ]
217
252
#[ command( next_help_heading = "DEVELOPER" ) ]
218
253
pub struct DeveloperCliOptions {
219
254
/// Outputs Onefetch in a specific format
220
255
#[ arg( long, short, value_name = "FORMAT" , value_enum) ]
256
+ #[ merge( skip) ]
221
257
pub output : Option < SerializationFormat > ,
222
258
/// If provided, outputs the completion file for given SHELL
223
259
#[ arg( long = "generate" , value_name = "SHELL" , value_enum) ]
260
+ #[ merge( skip) ]
224
261
pub completion : Option < Shell > ,
225
262
}
226
263
227
- #[ derive( Clone , Debug , Args , PartialEq , Eq , Default ) ]
264
+ #[ derive( Clone , Debug , Args , PartialEq , Eq , Default , Merge ) ]
228
265
#[ command( next_help_heading = "OTHER" ) ]
229
266
pub struct OtherCliOptions {
230
267
/// Prints out supported languages
231
268
#[ arg( long, short) ]
269
+ #[ merge( skip) ]
232
270
pub languages : bool ,
233
271
/// Prints out supported package managers
234
272
#[ arg( long, short) ]
273
+ #[ merge( skip) ]
235
274
pub package_managers : bool ,
236
275
}
237
276
238
277
impl Default for CliOptions {
239
278
fn default ( ) -> CliOptions {
240
279
CliOptions {
241
280
input : PathBuf :: from ( "." ) ,
281
+ config_path : None ,
242
282
info : InfoCliOptions :: default ( ) ,
243
283
text_formatting : TextForamttingCliOptions :: default ( ) ,
244
284
visuals : VisualsCliOptions :: default ( ) ,
@@ -302,6 +342,15 @@ impl Default for ImageCliOptions {
302
342
}
303
343
}
304
344
345
+ pub fn overwrite < T > ( l : & mut T , r : T ) {
346
+ * l = r;
347
+ }
348
+
349
+ pub fn overwrite_vec < T > ( l : & mut Vec < T > , mut r : Vec < T > ) {
350
+ l. clear ( ) ;
351
+ l. append ( & mut r) ;
352
+ }
353
+
305
354
pub fn print_supported_languages ( ) -> Result < ( ) > {
306
355
for l in Language :: iter ( ) {
307
356
println ! ( "{l}" ) ;
0 commit comments