bashkit 0.5.0

Awesomely fast virtual sandbox with bash and file system
Documentation
// GENERATED by bashkit-coreutils-port. DO NOT EDIT.
//
// Source: uutils/coreutils@39364b6 src/uu/shuf/
// Regenerate: cargo run -p bashkit-coreutils-port -- <UUTILS_DIR> shuf <REV>
//
// Original uutils licensed MIT; see THIRD_PARTY_LICENSES.

#![allow(unused_imports, dead_code)]
use clap::{Arg, ArgAction, Command, builder::ValueParser};
use std::ffi::OsString;
use std::ops::RangeInclusive;
use std::str::FromStr;
mod options {
    pub static ECHO: &str = "echo";
    pub static INPUT_RANGE: &str = "input-range";
    pub static HEAD_COUNT: &str = "head-count";
    pub static OUTPUT: &str = "output";
    pub static RANDOM_SOURCE: &str = "random-source";
    pub static RANDOM_SEED: &str = "random-seed";
    pub static REPEAT: &str = "repeat";
    pub static ZERO_TERMINATED: &str = "zero-terminated";
    pub static FILE_OR_ARGS: &str = "file-or-args";
}
/// Vendored stand-in for `uucore::format_usage`.
///
/// Upstream wraps the usage line with stylized "Usage:" prefix logic
/// driven by uucore's locale stack. For our purposes the raw string
/// is enough; clap's `override_usage` accepts the literal as-is.
fn format_usage(s: &str) -> String {
    s.to_string()
}
fn parse_range(input_range: &str) -> Result<RangeInclusive<u64>, String> {
    if let Some((from, to)) = input_range.split_once('-') {
        let begin = from.parse::<u64>().map_err(|e| e.to_string())?;
        let end = to.parse::<u64>().map_err(|e| e.to_string())?;
        if begin <= end || begin == end + 1 {
            Ok(begin..=end)
        } else {
            Err(::std::string::String::from("start exceeds end"))
        }
    } else {
        Err(::std::string::String::from("missing '-'"))
    }
}
pub fn shuf_command() -> Command {
    Command::new("shuf")
        .about(
            ::std::string::String::from(
                "Shuffle the input by outputting a random permutation of input lines.\nEach output permutation is equally likely.\nWith no FILE, or when FILE is -, read standard input.",
            ),
        )
        .version(env!("CARGO_PKG_VERSION"))
        .override_usage(
            format_usage(
                &::std::string::String::from(
                    "shuf [OPTION]... [FILE]\nshuf -e [OPTION]... [ARG]...\nshuf -i LO-HI [OPTION]...",
                ),
            ),
        )
        .infer_long_args(true)
        .arg(
            Arg::new(options::ECHO)
                .short('e')
                .long(options::ECHO)
                .help(::std::string::String::from("treat each ARG as an input line"))
                .action(ArgAction::SetTrue)
                .overrides_with(options::ECHO)
                .conflicts_with(options::INPUT_RANGE),
        )
        .arg(
            Arg::new(options::INPUT_RANGE)
                .short('i')
                .long(options::INPUT_RANGE)
                .value_name("LO-HI")
                .help(
                    ::std::string::String::from(
                        "treat each number LO through HI as an input line",
                    ),
                )
                .value_parser(parse_range)
                .conflicts_with(options::FILE_OR_ARGS),
        )
        .arg(
            Arg::new(options::HEAD_COUNT)
                .short('n')
                .long(options::HEAD_COUNT)
                .value_name("COUNT")
                .action(ArgAction::Append)
                .help(::std::string::String::from("output at most COUNT lines"))
                .value_parser(u64::from_str),
        )
        .arg(
            Arg::new(options::OUTPUT)
                .short('o')
                .long(options::OUTPUT)
                .value_name("FILE")
                .help(
                    ::std::string::String::from(
                        "write result to FILE instead of standard output",
                    ),
                )
                .value_parser(ValueParser::path_buf())
                .value_hint(clap::ValueHint::FilePath),
        )
        .arg(
            Arg::new(options::RANDOM_SEED)
                .long(options::RANDOM_SEED)
                .value_name("STRING")
                .help(
                    ::std::string::String::from(
                        "seed with STRING for reproducible output",
                    ),
                )
                .value_parser(ValueParser::string())
                .value_hint(clap::ValueHint::Other)
                .conflicts_with(options::RANDOM_SOURCE),
        )
        .arg(
            Arg::new(options::RANDOM_SOURCE)
                .long(options::RANDOM_SOURCE)
                .value_name("FILE")
                .help(::std::string::String::from("get random bytes from FILE"))
                .value_parser(ValueParser::path_buf())
                .value_hint(clap::ValueHint::FilePath),
        )
        .arg(
            Arg::new(options::REPEAT)
                .short('r')
                .long(options::REPEAT)
                .help(::std::string::String::from("output lines can be repeated"))
                .action(ArgAction::SetTrue)
                .overrides_with(options::REPEAT),
        )
        .arg(
            Arg::new(options::ZERO_TERMINATED)
                .short('z')
                .long(options::ZERO_TERMINATED)
                .help(::std::string::String::from("line delimiter is NUL, not newline"))
                .action(ArgAction::SetTrue)
                .overrides_with(options::ZERO_TERMINATED),
        )
        .arg(
            Arg::new(options::FILE_OR_ARGS)
                .action(ArgAction::Append)
                .value_parser(ValueParser::os_string())
                .value_hint(clap::ValueHint::FilePath),
        )
}