mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
Merge pull request #4393 from cakebaker/uucore_indent_usage_info
uucore: indent multiline usage info
This commit is contained in:
commit
8e1082458f
1 changed files with 15 additions and 3 deletions
|
@ -99,10 +99,13 @@ macro_rules! bin {
|
||||||
|
|
||||||
/// Generate the usage string for clap.
|
/// Generate the usage string for clap.
|
||||||
///
|
///
|
||||||
/// This function replaces all occurrences of `{}` with the execution phrase
|
/// This function does two things. It indents all but the first line to align
|
||||||
/// and returns the resulting `String`. It does **not** support
|
/// the lines because clap adds "Usage: " to the first line. And it replaces
|
||||||
/// more advanced formatting features such as `{0}`.
|
/// all occurrences of `{}` with the execution phrase and returns the resulting
|
||||||
|
/// `String`. It does **not** support more advanced formatting features such
|
||||||
|
/// as `{0}`.
|
||||||
pub fn format_usage(s: &str) -> String {
|
pub fn format_usage(s: &str) -> String {
|
||||||
|
let s = s.replace('\n', &format!("\n{}", " ".repeat(7)));
|
||||||
s.replace("{}", crate::execution_phrase())
|
s.replace("{}", crate::execution_phrase())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,4 +274,13 @@ mod tests {
|
||||||
test_invalid_utf8_args_lossy(os_str);
|
test_invalid_utf8_args_lossy(os_str);
|
||||||
test_invalid_utf8_args_ignore(os_str);
|
test_invalid_utf8_args_ignore(os_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_format_usage() {
|
||||||
|
assert_eq!(format_usage("expr EXPRESSION"), "expr EXPRESSION");
|
||||||
|
assert_eq!(
|
||||||
|
format_usage("expr EXPRESSION\nexpr OPTION"),
|
||||||
|
"expr EXPRESSION\n expr OPTION"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue