@@ -79,7 +79,7 @@ impl App {
79
79
pub fn config ( & self , inputs : & [ Input ] ) -> Result < Config > {
80
80
let style_components = self . style_components ( ) ?;
81
81
82
- let paging_mode = match self . matches . value_of ( "paging" ) {
82
+ let paging_mode = match self . matches . get_one :: < String > ( "paging" ) . map ( |s| s . as_str ( ) ) {
83
83
Some ( "always" ) => PagingMode :: Always ,
84
84
Some ( "never" ) => PagingMode :: Never ,
85
85
Some ( "auto" ) | None => {
@@ -107,13 +107,13 @@ impl App {
107
107
108
108
let mut syntax_mapping = SyntaxMapping :: builtin ( ) ;
109
109
110
- if let Some ( values) = self . matches . values_of ( "ignored-suffix" ) {
110
+ if let Some ( values) = self . matches . get_many :: < String > ( "ignored-suffix" ) {
111
111
for suffix in values {
112
112
syntax_mapping. insert_ignored_suffix ( suffix) ;
113
113
}
114
114
}
115
115
116
- if let Some ( values) = self . matches . values_of ( "map-syntax" ) {
116
+ if let Some ( values) = self . matches . get_many :: < String > ( "map-syntax" ) {
117
117
for from_to in values {
118
118
let parts: Vec < _ > = from_to. split ( ':' ) . collect ( ) ;
119
119
@@ -125,36 +125,43 @@ impl App {
125
125
}
126
126
}
127
127
128
- let maybe_term_width = self . matches . value_of ( "terminal-width" ) . and_then ( |w| {
129
- if w. starts_with ( '+' ) || w. starts_with ( '-' ) {
130
- // Treat argument as a delta to the current terminal width
131
- w. parse ( ) . ok ( ) . map ( |delta : i16 | {
132
- let old_width: u16 = Term :: stdout ( ) . size ( ) . 1 ;
133
- let new_width: i32 = i32:: from ( old_width) + i32:: from ( delta) ;
134
-
135
- if new_width <= 0 {
136
- old_width as usize
137
- } else {
138
- new_width as usize
139
- }
140
- } )
141
- } else {
142
- w. parse ( ) . ok ( )
143
- }
144
- } ) ;
128
+ let maybe_term_width = self
129
+ . matches
130
+ . get_one :: < String > ( "terminal-width" )
131
+ . and_then ( |w| {
132
+ if w. starts_with ( '+' ) || w. starts_with ( '-' ) {
133
+ // Treat argument as a delta to the current terminal width
134
+ w. parse ( ) . ok ( ) . map ( |delta : i16 | {
135
+ let old_width: u16 = Term :: stdout ( ) . size ( ) . 1 ;
136
+ let new_width: i32 = i32:: from ( old_width) + i32:: from ( delta) ;
137
+
138
+ if new_width <= 0 {
139
+ old_width as usize
140
+ } else {
141
+ new_width as usize
142
+ }
143
+ } )
144
+ } else {
145
+ w. parse ( ) . ok ( )
146
+ }
147
+ } ) ;
145
148
146
149
Ok ( Config {
147
150
true_color : is_truecolor_terminal ( ) ,
148
- language : self . matches . value_of ( "language" ) . or_else ( || {
149
- if self . matches . is_present ( "show-all" ) {
150
- Some ( "show-nonprintable" )
151
- } else {
152
- None
153
- }
154
- } ) ,
151
+ language : self
152
+ . matches
153
+ . get_one :: < String > ( "language" )
154
+ . map ( |s| s. as_str ( ) )
155
+ . or_else ( || {
156
+ if self . matches . is_present ( "show-all" ) {
157
+ Some ( "show-nonprintable" )
158
+ } else {
159
+ None
160
+ }
161
+ } ) ,
155
162
show_nonprintable : self . matches . is_present ( "show-all" ) ,
156
163
wrapping_mode : if self . interactive_output || maybe_term_width. is_some ( ) {
157
- match self . matches . value_of ( "wrap" ) {
164
+ match self . matches . get_one :: < String > ( "wrap" ) . map ( |s| s . as_str ( ) ) {
158
165
Some ( "character" ) => WrappingMode :: Character ,
159
166
Some ( "never" ) => WrappingMode :: NoWrapping ( true ) ,
160
167
Some ( "auto" ) | None => {
@@ -172,7 +179,7 @@ impl App {
172
179
WrappingMode :: NoWrapping ( false )
173
180
} ,
174
181
colored_output : self . matches . is_present ( "force-colorization" )
175
- || match self . matches . value_of ( "color" ) {
182
+ || match self . matches . get_one :: < String > ( "color" ) . map ( |s| s . as_str ( ) ) {
176
183
Some ( "always" ) => true ,
177
184
Some ( "never" ) => false ,
178
185
Some ( "auto" ) => env:: var_os ( "NO_COLOR" ) . is_none ( ) && self . interactive_output ,
@@ -181,12 +188,16 @@ impl App {
181
188
paging_mode,
182
189
term_width : maybe_term_width. unwrap_or ( Term :: stdout ( ) . size ( ) . 1 as usize ) ,
183
190
loop_through : !( self . interactive_output
184
- || self . matches . value_of ( "color" ) == Some ( "always" )
185
- || self . matches . value_of ( "decorations" ) == Some ( "always" )
191
+ || self . matches . get_one :: < String > ( "color" ) . map ( |s| s. as_str ( ) ) == Some ( "always" )
192
+ || self
193
+ . matches
194
+ . get_one :: < String > ( "decorations" )
195
+ . map ( |s| s. as_str ( ) )
196
+ == Some ( "always" )
186
197
|| self . matches . is_present ( "force-colorization" ) ) ,
187
198
tab_width : self
188
199
. matches
189
- . value_of ( "tabs" )
200
+ . get_one :: < String > ( "tabs" )
190
201
. map ( String :: from)
191
202
. or_else ( || env:: var ( "BAT_TABS" ) . ok ( ) )
192
203
. and_then ( |t| t. parse ( ) . ok ( ) )
@@ -199,7 +210,7 @@ impl App {
199
210
) ,
200
211
theme : self
201
212
. matches
202
- . value_of ( "theme" )
213
+ . get_one :: < String > ( "theme" )
203
214
. map ( String :: from)
204
215
. or_else ( || env:: var ( "BAT_THEME" ) . ok ( ) )
205
216
. map ( |s| {
@@ -214,28 +225,32 @@ impl App {
214
225
#[ cfg( feature = "git" ) ]
215
226
true => VisibleLines :: DiffContext (
216
227
self . matches
217
- . value_of ( "diff-context" )
228
+ . get_one :: < String > ( "diff-context" )
218
229
. and_then ( |t| t. parse ( ) . ok ( ) )
219
230
. unwrap_or ( 2 ) ,
220
231
) ,
221
232
222
233
_ => VisibleLines :: Ranges (
223
234
self . matches
224
- . values_of ( "line-range" )
225
- . map ( |vs| vs. map ( LineRange :: from) . collect ( ) )
235
+ . get_many :: < String > ( "line-range" )
236
+ . map ( |vs| vs. map ( |s| LineRange :: from ( s . as_str ( ) ) ) . collect ( ) )
226
237
. transpose ( ) ?
227
238
. map ( LineRanges :: from)
228
239
. unwrap_or_default ( ) ,
229
240
) ,
230
241
} ,
231
242
style_components,
232
243
syntax_mapping,
233
- pager : self . matches . value_of ( "pager" ) ,
234
- use_italic_text : self . matches . value_of ( "italic-text" ) == Some ( "always" ) ,
244
+ pager : self . matches . get_one :: < String > ( "pager" ) . map ( |s| s. as_str ( ) ) ,
245
+ use_italic_text : self
246
+ . matches
247
+ . get_one :: < String > ( "italic-text" )
248
+ . map ( |s| s. as_str ( ) )
249
+ == Some ( "always" ) ,
235
250
highlighted_lines : self
236
251
. matches
237
- . values_of ( "highlight-line" )
238
- . map ( |ws| ws. map ( LineRange :: from) . collect ( ) )
252
+ . get_many :: < String > ( "highlight-line" )
253
+ . map ( |ws| ws. map ( |s| LineRange :: from ( s . as_str ( ) ) ) . collect ( ) )
239
254
. transpose ( ) ?
240
255
. map ( LineRanges :: from)
241
256
. map ( HighlightedLineRanges )
@@ -292,8 +307,8 @@ impl App {
292
307
293
308
fn style_components ( & self ) -> Result < StyleComponents > {
294
309
let matches = & self . matches ;
295
- let mut styled_components =
296
- StyleComponents ( if matches. value_of ( "decorations" ) == Some ( "never" ) {
310
+ let mut styled_components = StyleComponents (
311
+ if matches. get_one :: < String > ( "decorations" ) . map ( |s| s . as_str ( ) ) == Some ( "never" ) {
297
312
HashSet :: new ( )
298
313
} else if matches. is_present ( "number" ) {
299
314
[ StyleComponent :: LineNumbers ] . iter ( ) . cloned ( ) . collect ( )
@@ -311,7 +326,7 @@ impl App {
311
326
. transpose ( ) ?;
312
327
313
328
matches
314
- . value_of ( "style" )
329
+ . get_one :: < String > ( "style" )
315
330
. map ( |styles| {
316
331
styles
317
332
. split ( ',' )
@@ -327,7 +342,8 @@ impl App {
327
342
acc. extend ( components. iter ( ) . cloned ( ) ) ;
328
343
acc
329
344
} )
330
- } ) ;
345
+ } ,
346
+ ) ;
331
347
332
348
// If `grid` is set, remove `rule` as it is a subset of `grid`, and print a warning.
333
349
if styled_components. grid ( ) && styled_components. 0 . remove ( & StyleComponent :: Rule ) {
0 commit comments