1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

Merge pull request #3137 from tertsdiepraam/docs-multiline-usage

docs: allow for multiline usage
This commit is contained in:
Sylvestre Ledru 2022-02-15 10:26:47 +01:00 committed by GitHub
commit 65467ab317
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 11 deletions

View file

@ -68,7 +68,14 @@ fn write_version(w: &mut impl Write, app: &App) -> io::Result<()> {
fn write_usage(w: &mut impl Write, app: &mut App, name: &str) -> io::Result<()> {
writeln!(w, "\n```")?;
let mut usage: String = app.render_usage().lines().nth(1).unwrap().trim().into();
let mut usage: String = app
.render_usage()
.lines()
.skip(1)
.map(|l| l.trim())
.filter(|l| !l.is_empty())
.collect::<Vec<_>>()
.join("\n");
usage = usage.replace(app.get_name(), name);
writeln!(w, "{}", usage)?;
writeln!(w, "```")

View file

@ -14,7 +14,7 @@ use std::fs::File;
use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write};
use uucore::display::Quotable;
use uucore::error::{FromIo, UResult, USimpleError};
use uucore::InvalidEncodingHandling;
use uucore::{execution_phrase, InvalidEncodingHandling};
mod rand_read_adapter;
@ -26,14 +26,9 @@ enum Mode {
static NAME: &str = "shuf";
static USAGE: &str = r#"shuf [OPTION]... [FILE]
or: shuf -e [OPTION]... [ARG]...
or: shuf -i LO-HI [OPTION]...
Write a random permutation of the input lines to standard output.
With no FILE, or when FILE is -, read standard input.
"#;
or: shuf -e [OPTION]... [ARG]...
or: shuf -i LO-HI [OPTION]..."#;
static ABOUT: &str = "Shuffle the input by outputting a random permutation of input lines. Each output permutation is equally likely.";
static TEMPLATE: &str = "Usage: {usage}\nMandatory arguments to long options are mandatory for short options too.\n{options}";
struct Options {
head_count: usize,
@ -60,7 +55,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any();
let matches = uu_app().get_matches_from(args);
let matches = uu_app()
.override_usage(&USAGE.replace(NAME, execution_phrase())[..])
.get_matches_from(args);
let mode = if let Some(args) = matches.values_of(options::ECHO) {
Mode::Echo(args.map(String::from).collect())
@ -125,7 +122,6 @@ pub fn uu_app<'a>() -> App<'a> {
.name(NAME)
.about(ABOUT)
.version(crate_version!())
.help_template(TEMPLATE)
.override_usage(USAGE)
.setting(AppSettings::InferLongArgs)
.arg(