1
- use std:: { borrow:: Cow , io:: IsTerminal } ;
2
-
1
+ #[ cfg( feature = "regex" ) ]
3
2
use regex:: Regex ;
3
+ #[ cfg( feature = "regex" ) ]
4
+ use std:: borrow:: Cow ;
5
+ #[ cfg( feature = "regex" ) ]
6
+ use std:: io:: IsTerminal ;
4
7
5
8
const HELP : & str = concat ! (
6
9
"tuc " ,
@@ -107,6 +110,7 @@ Send bug reports to: https://github.com/riquito/tuc/issues
107
110
"#
108
111
) ;
109
112
113
+ #[ cfg( feature = "regex" ) ]
110
114
fn get_colored_help ( text : & str ) -> String {
111
115
// This is very unprofessional but:
112
116
// - I'm playing around and there's no need to look for serious
@@ -159,6 +163,7 @@ fn get_colored_help(text: &str) -> String {
159
163
text. into_owned ( )
160
164
}
161
165
166
+ #[ cfg( feature = "regex" ) ]
162
167
fn get_colored_short_help ( text : & str ) -> String {
163
168
let text = Regex :: new ( r#"( tuc|echo|printf)"# )
164
169
. unwrap ( )
@@ -183,6 +188,7 @@ fn get_colored_short_help(text: &str) -> String {
183
188
text. into_owned ( )
184
189
}
185
190
191
+ #[ cfg( feature = "regex" ) ]
186
192
fn can_use_color ( ) -> bool {
187
193
let is_tty = std:: io:: stdout ( ) . is_terminal ( ) ;
188
194
let term = std:: env:: var ( "TERM" ) ;
@@ -195,6 +201,7 @@ fn can_use_color() -> bool {
195
201
&& no_color. is_err ( )
196
202
}
197
203
204
+ #[ cfg( feature = "regex" ) ]
198
205
pub fn get_help ( ) -> Cow < ' static , str > {
199
206
if can_use_color ( ) {
200
207
Cow :: Owned ( get_colored_help ( HELP ) )
@@ -203,10 +210,21 @@ pub fn get_help() -> Cow<'static, str> {
203
210
}
204
211
}
205
212
213
+ #[ cfg( feature = "regex" ) ]
206
214
pub fn get_short_help ( ) -> Cow < ' static , str > {
207
215
if can_use_color ( ) {
208
216
Cow :: Owned ( get_colored_short_help ( SHORT_HELP ) )
209
217
} else {
210
218
Cow :: Borrowed ( SHORT_HELP )
211
219
}
212
220
}
221
+
222
+ #[ cfg( not( feature = "regex" ) ) ]
223
+ pub fn get_help ( ) -> & ' static str {
224
+ HELP
225
+ }
226
+
227
+ #[ cfg( not( feature = "regex" ) ) ]
228
+ pub fn get_short_help ( ) -> & ' static str {
229
+ SHORT_HELP
230
+ }
0 commit comments