#![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";
fn format_usage(s: &str) -> String {
s.to_string()
}
pub static MKTEMP_ENV_DEFAULTS: &[crate::builtins::clap_env::EnvDefault] = &[];
#[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)),
)
}