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/mktemp/
// Regenerate: cargo run -p bashkit-coreutils-port -- <UUTILS_DIR> mktemp <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;
static OPT_DIRECTORY: &str = "directory";
static OPT_DRY_RUN: &str = "dry-run";
static OPT_QUIET: &str = "quiet";
static OPT_SUFFIX: &str = "suffix";
static OPT_TMPDIR: &str = "tmpdir";
static OPT_P: &str = "p";
static OPT_T: &str = "t";
static ARG_TEMPLATE: &str = "template";
/// 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 MKTEMP_ENV_DEFAULTS: &[crate::builtins::clap_env::EnvDefault] = &[];
/// Custom parser that converts empty string to `None`, and non-empty string to
/// `Some(PathBuf)`.
///
/// This parser is used for the `-p` and `--tmpdir` options where an empty string
/// argument should be treated as "not provided", causing mktemp to fall back to
/// using the `$TMPDIR` environment variable or the system's default temporary
/// directory.
///
/// # Examples
///
/// - Empty string `""` -> `None`
/// - Non-empty string `"/tmp"` -> `Some(PathBuf::from("/tmp"))`
///
/// This handles the special case where users can pass an empty directory name
/// to explicitly request fallback behavior.
#[derive(Clone, Debug)]
struct OptionalPathBufParser;
impl TypedValueParser for OptionalPathBufParser {
    type Value = Option<PathBuf>;
    fn parse_ref(
        &self,
        _cmd: &Command,
        _arg: Option<&Arg>,
        value: &OsStr,
    ) -> Result<Self::Value, clap::Error> {
        if value.is_empty() {
            Ok(None)
        } else {
            Ok(Some(PathBuf::from(value)))
        }
    }
}
impl ValueParserFactory for OptionalPathBufParser {
    type Parser = Self;
    fn value_parser() -> Self::Parser {
        Self
    }
}
pub fn mktemp_command() -> Command {
    Command::new("mktemp")
        .version(env!("CARGO_PKG_VERSION"))
        .about(::std::string::String::from("Create a temporary file or directory."))
        .override_usage(
            format_usage(&::std::string::String::from("mktemp [OPTION]... [TEMPLATE]")),
        )
        .infer_long_args(true)
        .arg(
            Arg::new(OPT_DIRECTORY)
                .short('d')
                .long(OPT_DIRECTORY)
                .help(::std::string::String::from("Make a directory instead of a file"))
                .action(ArgAction::SetTrue),
        )
        .arg(
            Arg::new(OPT_DRY_RUN)
                .short('u')
                .long(OPT_DRY_RUN)
                .help(
                    ::std::string::String::from(
                        "do not create anything; merely print a name (unsafe)",
                    ),
                )
                .action(ArgAction::SetTrue),
        )
        .arg(
            Arg::new(OPT_QUIET)
                .short('q')
                .long("quiet")
                .help(::std::string::String::from("Fail silently if an error occurs."))
                .action(ArgAction::SetTrue),
        )
        .arg(
            Arg::new(OPT_SUFFIX)
                .long(OPT_SUFFIX)
                .help(
                    ::std::string::String::from(
                        "append SUFFIX to TEMPLATE; SUFFIX must not contain a path separator. This option is implied if TEMPLATE does not end with X.",
                    ),
                )
                .value_name("SUFFIX")
                .value_parser(clap::value_parser!(OsString)),
        )
        .arg(
            Arg::new(OPT_P)
                .short('p')
                .help(::std::string::String::from("short form of --tmpdir"))
                .value_name("DIR")
                .num_args(1)
                .value_parser(OptionalPathBufParser)
                .value_hint(clap::ValueHint::DirPath),
        )
        .arg(
            Arg::new(OPT_TMPDIR)
                .long(OPT_TMPDIR)
                .help(
                    ::std::string::String::from(
                        "interpret TEMPLATE relative to DIR; if DIR is not specified, use $TMPDIR ($TMP on windows) if set, else /tmp. With this option, TEMPLATE must not be an absolute name; unlike with -t, TEMPLATE may contain slashes, but mktemp creates only the final component",
                    ),
                )
                .value_name("DIR")
                .num_args(0..=1)
                .require_equals(true)
                .overrides_with(OPT_P)
                .value_parser(OptionalPathBufParser)
                .value_hint(clap::ValueHint::DirPath),
        )
        .arg(
            Arg::new(OPT_T)
                .short('t')
                .help(
                    ::std::string::String::from(
                        "Generate a template (using the supplied prefix and TMPDIR (TMP on windows) if set) to create a filename template [deprecated]",
                    ),
                )
                .action(ArgAction::SetTrue),
        )
        .arg(
            Arg::new(ARG_TEMPLATE)
                .num_args(..=1)
                .value_parser(clap::value_parser!(OsString)),
        )
}