Skip to content

Commit c6d6740

Browse files
committed
Regex is required for colored help
1 parent 353921f commit c6d6740

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/help.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
use std::{borrow::Cow, io::IsTerminal};
2-
1+
#[cfg(feature = "regex")]
32
use regex::Regex;
3+
#[cfg(feature = "regex")]
4+
use std::borrow::Cow;
5+
#[cfg(feature = "regex")]
6+
use std::io::IsTerminal;
47

58
const HELP: &str = concat!(
69
"tuc ",
@@ -107,6 +110,7 @@ Send bug reports to: https://github.com/riquito/tuc/issues
107110
"#
108111
);
109112

113+
#[cfg(feature = "regex")]
110114
fn get_colored_help(text: &str) -> String {
111115
// This is very unprofessional but:
112116
// - I'm playing around and there's no need to look for serious
@@ -159,6 +163,7 @@ fn get_colored_help(text: &str) -> String {
159163
text.into_owned()
160164
}
161165

166+
#[cfg(feature = "regex")]
162167
fn get_colored_short_help(text: &str) -> String {
163168
let text = Regex::new(r#"( tuc|echo|printf)"#)
164169
.unwrap()
@@ -183,6 +188,7 @@ fn get_colored_short_help(text: &str) -> String {
183188
text.into_owned()
184189
}
185190

191+
#[cfg(feature = "regex")]
186192
fn can_use_color() -> bool {
187193
let is_tty = std::io::stdout().is_terminal();
188194
let term = std::env::var("TERM");
@@ -195,6 +201,7 @@ fn can_use_color() -> bool {
195201
&& no_color.is_err()
196202
}
197203

204+
#[cfg(feature = "regex")]
198205
pub fn get_help() -> Cow<'static, str> {
199206
if can_use_color() {
200207
Cow::Owned(get_colored_help(HELP))
@@ -203,10 +210,21 @@ pub fn get_help() -> Cow<'static, str> {
203210
}
204211
}
205212

213+
#[cfg(feature = "regex")]
206214
pub fn get_short_help() -> Cow<'static, str> {
207215
if can_use_color() {
208216
Cow::Owned(get_colored_short_help(SHORT_HELP))
209217
} else {
210218
Cow::Borrowed(SHORT_HELP)
211219
}
212220
}
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

Comments
 (0)