bashkit 0.8.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/realpath/
// Regenerate: cargo run -p bashkit-coreutils-port -- <UUTILS_DIR> realpath <REV>
//
// Original uutils licensed MIT; see THIRD_PARTY_LICENSES.

#![allow(unused_imports, dead_code)]
use clap::builder::{
    NonEmptyStringValueParser, PossibleValue, PossibleValuesParser, TypedValueParser, ValueParser,
    ValueParserFactory,
};
use clap::{Arg, ArgAction, Command};
use std::ffi::{OsStr, OsString};
use std::ops::RangeInclusive;
use std::path::PathBuf;
use std::str::FromStr;
const OPT_QUIET: &str = "quiet";
const OPT_STRIP: &str = "strip";
const OPT_ZERO: &str = "zero";
const OPT_PHYSICAL: &str = "physical";
const OPT_LOGICAL: &str = "logical";
const OPT_CANONICALIZE_MISSING: &str = "canonicalize-missing";
const OPT_CANONICALIZE: &str = "canonicalize";
const OPT_CANONICALIZE_EXISTING: &str = "canonicalize-existing";
const OPT_RELATIVE_TO: &str = "relative-to";
const OPT_RELATIVE_BASE: &str = "relative-base";
const ARG_FILES: &str = "files";
/// 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()
}
/// Sidecar harvest of every `Arg::env(...)` annotation the codegen
/// stripped from the runtime Arg chain (TM-INF-024). Consumed by
/// `crate::builtins::clap_env::apply_env_defaults` so bashkit's
/// virtual `ctx.env` — never `std::env` — drives clap's env-default
/// path. Order matches the chain order in the original `uu_app()`.
pub static REALPATH_ENV_DEFAULTS: &[crate::builtins::clap_env::EnvDefault] = &[];
/// Custom parser that validates `OsString` is not empty
#[derive(Clone, Debug)]
struct NonEmptyOsStringParser;
impl TypedValueParser for NonEmptyOsStringParser {
    type Value = OsString;
    fn parse_ref(
        &self,
        _cmd: &Command,
        _arg: Option<&Arg>,
        value: &OsStr,
    ) -> Result<Self::Value, clap::Error> {
        if value.is_empty() {
            let mut err = clap::Error::new(clap::error::ErrorKind::ValueValidation);
            err.insert(
                clap::error::ContextKind::Custom,
                clap::error::ContextValue::String(::std::string::String::from(
                    "invalid operand: empty string",
                )),
            );
            return Err(err);
        }
        Ok(value.to_os_string())
    }
}
impl ValueParserFactory for NonEmptyOsStringParser {
    type Parser = Self;
    fn value_parser() -> Self::Parser {
        Self
    }
}
pub fn realpath_command() -> Command {
    Command::new("realpath")
        .version(env!("CARGO_PKG_VERSION"))
        .about(::std::string::String::from("Print the resolved path"))
        .override_usage(
            format_usage(&::std::string::String::from("realpath [OPTION]... FILE...")),
        )
        .infer_long_args(true)
        .arg(
            Arg::new(OPT_QUIET)
                .short('q')
                .long(OPT_QUIET)
                .help(
                    ::std::string::String::from(
                        "Do not print warnings for invalid paths",
                    ),
                )
                .action(ArgAction::SetTrue),
        )
        .arg(
            Arg::new(OPT_STRIP)
                .short('s')
                .long(OPT_STRIP)
                .visible_alias("no-symlinks")
                .help(
                    ::std::string::String::from(
                        "Only strip '.' and '..' components, but don't resolve symbolic links",
                    ),
                )
                .action(ArgAction::SetTrue),
        )
        .arg(
            Arg::new(OPT_ZERO)
                .short('z')
                .long(OPT_ZERO)
                .help(
                    ::std::string::String::from(
                        "Separate output filenames with \\0 rather than newline",
                    ),
                )
                .action(ArgAction::SetTrue),
        )
        .arg(
            Arg::new(OPT_LOGICAL)
                .short('L')
                .long(OPT_LOGICAL)
                .help(
                    ::std::string::String::from(
                        "resolve '..' components before symlinks",
                    ),
                )
                .action(ArgAction::SetTrue),
        )
        .arg(
            Arg::new(OPT_PHYSICAL)
                .short('P')
                .long(OPT_PHYSICAL)
                .overrides_with_all([OPT_STRIP, OPT_LOGICAL])
                .help(
                    ::std::string::String::from(
                        "resolve symlinks as encountered (default)",
                    ),
                )
                .action(ArgAction::SetTrue),
        )
        .arg(
            Arg::new(OPT_CANONICALIZE)
                .short('E')
                .long(OPT_CANONICALIZE)
                .overrides_with_all([
                    OPT_CANONICALIZE_EXISTING,
                    OPT_CANONICALIZE_MISSING,
                ])
                .help(
                    ::std::string::String::from(
                        "all but the last component must exist (default)",
                    ),
                )
                .action(ArgAction::SetTrue),
        )
        .arg(
            Arg::new(OPT_CANONICALIZE_EXISTING)
                .short('e')
                .long(OPT_CANONICALIZE_EXISTING)
                .overrides_with_all([OPT_CANONICALIZE, OPT_CANONICALIZE_MISSING])
                .help(
                    ::std::string::String::from(
                        "canonicalize by following every symlink in every component of the given name recursively, all components must exist",
                    ),
                )
                .action(ArgAction::SetTrue),
        )
        .arg(
            Arg::new(OPT_CANONICALIZE_MISSING)
                .short('m')
                .long(OPT_CANONICALIZE_MISSING)
                .overrides_with_all([OPT_CANONICALIZE, OPT_CANONICALIZE_EXISTING])
                .help(
                    ::std::string::String::from(
                        "canonicalize by following every symlink in every component of the given name recursively, without requirements on components existence",
                    ),
                )
                .action(ArgAction::SetTrue),
        )
        .arg(
            Arg::new(OPT_RELATIVE_TO)
                .long(OPT_RELATIVE_TO)
                .value_name("DIR")
                .value_parser(NonEmptyOsStringParser)
                .help(
                    ::std::string::String::from(
                        "print the resolved path relative to DIR",
                    ),
                ),
        )
        .arg(
            Arg::new(OPT_RELATIVE_BASE)
                .long(OPT_RELATIVE_BASE)
                .value_name("DIR")
                .value_parser(NonEmptyOsStringParser)
                .help(
                    ::std::string::String::from(
                        "print absolute paths unless paths below DIR",
                    ),
                ),
        )
        .arg(
            Arg::new(ARG_FILES)
                .action(ArgAction::Append)
                .required(true)
                .value_parser(NonEmptyOsStringParser)
                .value_hint(clap::ValueHint::AnyPath),
        )
}