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