use std::ffi::{OsStr, OsString};
use winnow_args::response::{ResponseFiles, expand};
use winnow_args::value::Spanned;
use winnow_args::{Args, Occurrence};
#[derive(Debug, Args)]
#[arg(
name = "ld",
long_only,
disable_help_short,
after_help = "Long options take one dash or two (`-shared`), except those listed with two only \
where one dash would read as a short option's value. `-z KEYWORD` is printed as \
the option it stands for; `@FILE` is replaced by the words in the file. A word \
that is no option is an input; an unknown option is kept as `Unknown`, and \
several short options in one word (`-sS`) as `Grouped` before them."
)]
struct Cli {
#[arg(sequence, unknown)]
items: Vec<Item>,
}
#[allow(dead_code, reason = "the `-z` variants' values are only printed")]
#[derive(Occurrence, Debug)]
#[arg(allow_hyphen_values, keep_equals)]
enum Item {
#[arg(short = 'o')]
OutputShort(OsString),
#[arg(long = "output", two_dashes)]
Output(OsString),
#[arg(long = "dynamic-linker")]
DynamicLinker(OsString),
#[arg(short = 'I')]
DynamicLinkerShort(OsString),
#[arg(long = "no-dynamic-linker")]
NoDynamicLinker,
#[arg(short = 'v')]
ShortVLower,
#[arg(long = "version")]
Version,
#[arg(short = 'V')]
ShortV,
#[arg(long = "mllvm")]
Mllvm(OsString),
#[arg(long = "end-lib")]
EndLib,
#[arg(long = "export-dynamic")]
ExportDynamic,
#[arg(short = 'E')]
ExportDynamicShort,
#[arg(long = "no-export-dynamic")]
NoExportDynamic,
#[arg(long = "Bsymbolic")]
Bsymbolic,
#[arg(long = "Bsymbolic-functions")]
BsymbolicFunctions,
#[arg(long = "Bsymbolic-non-weak")]
BsymbolicNonWeak,
#[arg(long = "Bsymbolic-non-weak-functions")]
BsymbolicNonWeakFunctions,
#[arg(long = "Bno-symbolic")]
BnoSymbolic,
#[arg(long = "exclude-libs")]
ExcludeLibs(OsString),
#[arg(short = 'q')]
EmitRelocsShort,
#[arg(long = "emit-relocs")]
EmitRelocs,
#[arg(long = "Map")]
Map(OsString),
#[arg(long = "print-dependencies")]
PrintDependencies,
#[arg(long = "print-map")]
PrintMap,
#[arg(short = 'M')]
PrintMapShort,
#[arg(long = "Bstatic")]
Bstatic,
#[arg(long = "dn")]
Dn,
#[arg(long = "static")]
Static,
#[arg(long = "Bdynamic")]
Bdynamic,
#[arg(long = "dy")]
Dy,
#[arg(long = "shared")]
Shared,
#[arg(long = "Bshareable")]
Bshareable,
#[arg(long = "spare-dynamic-tags")]
SpareDynamicTags(OsString),
#[arg(long = "spare-program-headers")]
SpareProgramHeaders(OsString),
#[arg(long = "start-lib")]
StartLib,
#[arg(long = "start-stop")]
StartStop,
#[arg(long = "dependency-file")]
DependencyFile(OsString),
#[arg(long = "defsym")]
Defsym(OsString),
#[arg(long = ":lto-pass2")]
InternalLtoPass2,
#[arg(long = ":ignore-ir-file")]
InternalIgnoreIrFile(OsString),
#[arg(long = "demangle")]
Demangle,
#[arg(long = "no-demangle")]
NoDemangle,
#[arg(long = "detach")]
Detach,
#[arg(long = "no-detach")]
NoDetach,
#[arg(long = "default-symver")]
DefaultSymver,
#[arg(long = "noinhibit-exec")]
NoinhibitExec,
#[arg(long = "shuffle-sections", require_equals, default_missing = "\0")]
ShuffleSections(OsString),
#[arg(long = "reverse-sections")]
ReverseSections,
#[arg(long = "rosegment")]
Rosegment,
#[arg(long = "no-rosegment")]
NoRosegment,
#[arg(short = 'y')]
TraceSymbolShort(OsString),
#[arg(long = "trace-symbol")]
TraceSymbol(OsString),
#[arg(long = "filler")]
Filler(OsString),
#[arg(short = 'L')]
LibraryPathShort(OsString),
#[arg(long = "library-path")]
LibraryPath(OsString),
#[arg(long = "sysroot")]
Sysroot(OsString),
#[arg(long = "unique")]
Unique(OsString),
#[arg(long = "unresolved-symbols")]
UnresolvedSymbols(OsString),
#[arg(long = "undefined-glob", two_dashes)]
UndefinedGlob(OsString),
#[arg(long = "require-defined")]
RequireDefined(OsString),
#[arg(long = "init")]
Init(OsString),
#[arg(long = "fini")]
Fini(OsString),
#[arg(long = "hash-style")]
HashStyle(OsString),
#[arg(long = "soname")]
Soname(OsString),
#[arg(short = 'h')]
SonameShort(OsString),
#[arg(long = "audit")]
Audit(OsString),
#[arg(long = "depaudit")]
Depaudit(OsString),
#[arg(short = 'P')]
DepauditShort(OsString),
#[arg(long = "allow-multiple-definition")]
AllowMultipleDefinition,
#[arg(long = "apply-dynamic-relocs")]
ApplyDynamicRelocs,
#[arg(long = "no-apply-dynamic-relocs")]
NoApplyDynamicRelocs,
#[arg(long = "trace")]
Trace,
#[arg(long = "eh-frame-hdr")]
EhFrameHdr,
#[arg(long = "no-eh-frame-hdr")]
NoEhFrameHdr,
#[arg(long = "pie")]
Pie,
#[arg(long = "pic-executable")]
PicExecutable,
#[arg(long = "no-pie")]
NoPie,
#[arg(long = "no-pic-executable")]
NoPicExecutable,
#[arg(long = "nopie")]
Nopie,
#[arg(long = "relax")]
Relax,
#[arg(long = "no-relax")]
NoRelax,
#[arg(long = "gdb-index")]
GdbIndex,
#[arg(long = "no-gdb-index")]
NoGdbIndex,
#[arg(short = 'r')]
RelocatableShort,
#[arg(long = "relocatable")]
Relocatable,
#[arg(long = "relocatable-merge-sections")]
RelocatableMergeSections,
#[arg(long = "perf")]
Perf,
#[arg(long = "pack-dyn-relocs", require_equals)]
PackDynRelocs(OsString),
#[arg(long = "use-android-relr-tags", two_dashes)]
UseAndroidRelrTags,
#[arg(long = "no-use-android-relr-tags")]
NoUseAndroidRelrTags,
#[arg(long = "package-metadata", require_equals)]
PackageMetadata(OsString),
#[arg(long = "stats")]
Stats,
#[arg(short = 'C')]
DirectoryShort(OsString),
#[arg(long = "directory")]
Directory(OsString),
#[arg(long = "chroot")]
Chroot(OsString),
#[arg(long = "color-diagnostics", require_equals, default_missing = "\0")]
ColorDiagnostics(OsString),
#[arg(long = "no-color-diagnostics")]
NoColorDiagnostics,
#[arg(long = "warn-common")]
WarnCommon,
#[arg(long = "no-warn-common")]
NoWarnCommon,
#[arg(long = "warn-once")]
IgnoredWarnOnce,
#[arg(long = "warn-shared-textrel")]
WarnSharedTextrel,
#[arg(long = "warn-textrel")]
WarnTextrel,
#[arg(long = "enable-new-dtags")]
EnableNewDtags,
#[arg(long = "disable-new-dtags")]
DisableNewDtags,
#[arg(long = "execute-only", two_dashes)]
ExecuteOnly,
#[arg(long = "zero-to-bss")]
ZeroToBss,
#[arg(long = "compress-debug-sections")]
CompressDebugSections(OsString),
#[arg(long = "wrap")]
Wrap(OsString),
#[arg(long = "omagic", two_dashes)]
Omagic,
#[arg(short = 'N')]
OmagicShort,
#[arg(long = "no-omagic", two_dashes)]
NoOmagic,
#[arg(long = "oformat", two_dashes)]
Oformat(OsString),
#[arg(long = "retain-symbols-file")]
RetainSymbolsFile(OsString),
#[arg(long = "section-align")]
SectionAlign(OsString),
#[arg(long = "section-start")]
SectionStart(OsString),
#[arg(long = "section-order")]
SectionOrder(OsString),
#[arg(long = "Tbss")]
Tbss(OsString),
#[arg(long = "Tdata")]
Tdata(OsString),
#[arg(long = "Ttext")]
Ttext(OsString),
#[arg(long = "Ttext-segment")]
TtextSegment(OsString),
#[arg(long = "repro")]
Repro,
#[arg(long = "no-undefined")]
NoUndefined,
#[arg(long = "separate-debug-file", require_equals, default_missing = "\0")]
SeparateDebugFile(OsString),
#[arg(long = "no-separate-debug-file")]
NoSeparateDebugFile,
#[arg(long = "nmagic")]
Nmagic,
#[arg(long = "no-nmagic")]
NoNmagic,
#[arg(long = "fatal-warnings")]
FatalWarnings,
#[arg(long = "no-fatal-warnings")]
NoFatalWarnings,
#[arg(short = 'w')]
NoWarningsShort,
#[arg(long = "no-warnings")]
NoWarnings,
#[arg(long = "fork")]
Fork,
#[arg(long = "no-fork")]
NoFork,
#[arg(long = "gc-sections")]
GcSections,
#[arg(long = "no-gc-sections")]
NoGcSections,
#[arg(long = "print-gc-sections", require_equals, default_missing = "\0")]
PrintGcSections(OsString),
#[arg(long = "no-print-gc-sections")]
NoPrintGcSections,
#[arg(long = "discard-section")]
DiscardSection(OsString),
#[arg(long = "no-discard-section")]
NoDiscardSection(OsString),
#[arg(long = "icf")]
Icf(OsString),
#[arg(long = "no-icf")]
NoIcf,
#[arg(long = "ignore-data-address-equality")]
IgnoreDataAddressEquality,
#[arg(long = "image-base")]
ImageBase(OsString),
#[arg(long = "physical-image-base")]
PhysicalImageBase(OsString),
#[arg(long = "print-icf-sections", require_equals, default_missing = "\0")]
PrintIcfSections(OsString),
#[arg(long = "no-print-icf-sections")]
NoPrintIcfSections,
#[arg(long = "quick-exit")]
QuickExit,
#[arg(long = "no-quick-exit")]
NoQuickExit,
#[arg(long = "plugin")]
Plugin(OsString),
#[arg(long = "plugin-opt")]
PluginOpt(OsString),
#[arg(long = "lto-cs-profile-generate", two_dashes)]
LtoCsProfileGenerate,
#[arg(long = "lto-debug-pass-manager", two_dashes)]
LtoDebugPassManager,
#[arg(long = "disable-verify")]
DisableVerify,
#[arg(long = "lto-emit-asm", two_dashes)]
LtoEmitAsm,
#[arg(long = "no-legacy-pass-manager")]
NoLegacyPassManager,
#[arg(long = "no-lto-legacy-pass-manager")]
NoLtoLegacyPassManager,
#[arg(long = "opt-remarks-with-hotness", two_dashes)]
OptRemarksWithHotness,
#[arg(long = "lto-pseudo-probe-for-profiling")]
LtoPseudoProbeForProfiling,
#[arg(long = "save-temps")]
SaveTemps,
#[arg(long = "thinlto-emit-imports-files")]
ThinltoEmitImportsFiles,
#[arg(long = "thinlto-index-only", require_equals, default_missing = "\0")]
ThinltoIndexOnly(OsString),
#[arg(long = "lto-cs-profile-file", two_dashes)]
LtoCsProfileFile(OsString),
#[arg(long = "lto-partitions", two_dashes)]
LtoPartitions(OsString),
#[arg(long = "lto-obj-path", two_dashes)]
LtoObjPath(OsString),
#[arg(long = "opt-remarks-filename", two_dashes)]
OptRemarksFilename(OsString),
#[arg(long = "opt-remarks-format", two_dashes)]
OptRemarksFormat(OsString),
#[arg(long = "opt-remarks-hotness-threshold", two_dashes)]
OptRemarksHotnessThreshold(OsString),
#[arg(long = "opt-remarks-passes", two_dashes)]
OptRemarksPasses(OsString),
#[arg(long = "lto-sample-profile", two_dashes)]
LtoSampleProfile(OsString),
#[arg(long = "thinlto-object-suffix-replace")]
ThinltoObjectSuffixReplace(OsString),
#[arg(long = "thinlto-prefix-replace")]
ThinltoPrefixReplace(OsString),
#[arg(long = "thinlto-cache-dir")]
ThinltoCacheDir(OsString),
#[arg(long = "thinlto-cache-policy")]
ThinltoCachePolicy(OsString),
#[arg(long = "thinlto-jobs")]
ThinltoJobs(OsString),
#[arg(long = "thread-count")]
ThreadCount(OsString),
#[arg(long = "threads", require_equals, default_missing = "\0")]
Threads(OsString),
#[arg(long = "no-threads")]
NoThreads,
#[arg(long = "discard-all")]
DiscardAll,
#[arg(short = 'x')]
DiscardAllShort,
#[arg(long = "discard-locals")]
DiscardLocals,
#[arg(short = 'X')]
DiscardLocalsShort,
#[arg(long = "discard-none")]
DiscardNone,
#[arg(long = "strip-all")]
StripAll,
#[arg(short = 's')]
StripAllShort,
#[arg(long = "strip-debug")]
StripDebug,
#[arg(short = 'S')]
StripDebugShort,
#[arg(long = "warn-unresolved-symbols")]
WarnUnresolvedSymbols,
#[arg(long = "error-unresolved-symbols")]
ErrorUnresolvedSymbols,
#[arg(long = "rpath")]
Rpath(OsString),
#[arg(short = 'R')]
ShortR(OsString),
#[arg(long = "undefined-version", two_dashes)]
UndefinedVersion,
#[arg(long = "no-undefined-version")]
NoUndefinedVersion,
#[arg(long = "undefined")]
Undefined(OsString),
#[arg(short = 'u')]
UndefinedShort(OsString),
#[arg(long = "build-id", require_equals, default_missing = "\0")]
BuildId(OsString),
#[arg(long = "no-build-id")]
NoBuildId,
#[arg(long = "be8")]
Be8,
#[arg(long = "be32")]
Be32,
#[arg(long = "format", two_dashes)]
Format(OsString),
#[arg(short = 'b')]
FormatShort(OsString),
#[arg(long = "fuse-ld")]
IgnoredFuseLd(OsString),
#[arg(long = "allow-shlib-undefined")]
AllowShlibUndefined,
#[arg(long = "no-allow-shlib-undefined")]
NoAllowShlibUndefined,
#[arg(short = 'O')]
IgnoredShortO(OsString),
#[arg(long = "EB")]
IgnoredEB,
#[arg(long = "EL")]
IgnoredEL,
#[arg(long = "O0")]
IgnoredO0,
#[arg(long = "O1")]
IgnoredO1,
#[arg(long = "O2")]
IgnoredO2,
#[arg(long = "verbose")]
IgnoredVerbose,
#[arg(long = "start-group")]
IgnoredStartGroup,
#[arg(long = "end-group")]
IgnoredEndGroup,
#[arg(short = '(')]
IgnoredOpenParen,
#[arg(short = ')')]
IgnoredCloseParen,
#[arg(long = "nostdlib")]
IgnoredNostdlib,
#[arg(long = "no-add-needed")]
IgnoredNoAddNeeded,
#[arg(long = "no-call-graph-profile-sort")]
IgnoredNoCallGraphProfileSort,
#[arg(long = "no-copy-dt-needed-entries")]
IgnoredNoCopyDtNeededEntries,
#[arg(long = "sort-section")]
IgnoredSortSection(OsString),
#[arg(long = "sort-common")]
IgnoredSortCommon,
#[arg(long = "dc")]
IgnoredDc,
#[arg(long = "dp")]
IgnoredDp,
#[arg(long = "fix-cortex-a53-835769")]
IgnoredFixCortexA53835769,
#[arg(long = "fix-cortex-a53-843419")]
IgnoredFixCortexA53843419,
#[arg(long = "nodefaultlibs")]
IgnoredNodefaultlibs,
#[arg(long = "warn-constructors")]
IgnoredWarnConstructors,
#[arg(long = "warn-execstack")]
IgnoredWarnExecstack,
#[arg(long = "no-warn-execstack")]
IgnoredNoWarnExecstack,
#[arg(long = "long-plt")]
IgnoredLongPlt,
#[arg(long = "secure-plt")]
IgnoredSecurePlt,
#[arg(long = "rpath-link")]
IgnoredRpathLink(OsString),
#[arg(long = "no-keep-memory")]
IgnoredNoKeepMemory,
#[arg(long = "max-cache-size")]
IgnoredMaxCacheSize(OsString),
#[arg(long = "mmap-output-file", two_dashes)]
IgnoredMmapOutputFile,
#[arg(long = "no-mmap-output-file")]
IgnoredNoMmapOutputFile,
#[arg(short = 'm')]
ShortMLower(OsString),
#[arg(long = "filter")]
Filter(OsString),
#[arg(short = 'F')]
FilterShort(OsString),
#[arg(long = "auxiliary")]
Auxiliary(OsString),
#[arg(short = 'f')]
AuxiliaryShort(OsString),
#[arg(long = "version-script")]
VersionScript(OsString),
#[arg(long = "dynamic-list")]
DynamicList(OsString),
#[arg(long = "dynamic-list-data")]
DynamicListData,
#[arg(long = "export-dynamic-symbol", two_dashes)]
ExportDynamicSymbol(OsString),
#[arg(long = "export-dynamic-symbol-list", two_dashes)]
ExportDynamicSymbolList(OsString),
#[arg(long = "entry")]
Entry(OsString),
#[arg(short = 'e')]
EntryShort(OsString),
#[arg(long = "as-needed")]
AsNeeded,
#[arg(long = "no-as-needed")]
NoAsNeeded,
#[arg(long = "whole-archive")]
WholeArchive,
#[arg(long = "no-whole-archive")]
NoWholeArchive,
#[arg(long = "library", two_dashes)]
Library(OsString),
#[arg(short = 'l', prefix)]
LibraryShort(OsString),
#[arg(long = "script")]
Script(OsString),
#[arg(short = 'T')]
ScriptShort(OsString),
#[arg(long = "push-state")]
PushState,
#[arg(long = "pop-state")]
PopState,
#[arg(short = 'z')]
Z(Spanned<OsString>),
#[arg(skip)]
ZNow,
#[arg(skip)]
ZLazy,
#[arg(skip)]
ZCetReportNone,
#[arg(skip)]
ZCetReportWarning,
#[arg(skip)]
ZCetReportError,
#[arg(skip)]
ZBtiReportNone,
#[arg(skip)]
ZBtiReportWarning,
#[arg(skip)]
ZBtiReportError,
#[arg(skip)]
ZGcsReportNone,
#[arg(skip)]
ZGcsReportWarning,
#[arg(skip)]
ZGcsReportError,
#[arg(skip)]
ZExecstack,
#[arg(skip)]
ZExecstackIfNeeded,
#[arg(skip)]
ZMaxPageSize(OsString),
#[arg(skip)]
ZStartStopVisibilityProtected,
#[arg(skip)]
ZStartStopVisibilityHidden,
#[arg(skip)]
ZNoexecstack,
#[arg(skip)]
ZRelro,
#[arg(skip)]
ZNorelro,
#[arg(skip)]
ZUndefs,
#[arg(skip)]
ZNodlopen,
#[arg(skip)]
ZNodelete,
#[arg(skip)]
ZNocopyreloc,
#[arg(skip)]
ZNodump,
#[arg(skip)]
ZInitfirst,
#[arg(skip)]
ZInterpose,
#[arg(skip)]
ZIbt,
#[arg(skip)]
ZIbtplt,
#[arg(skip)]
ZForceBti,
#[arg(skip)]
ZPacPlt,
#[arg(skip)]
ZGcsImplicit,
#[arg(skip)]
ZGcsNever,
#[arg(skip)]
ZGcsAlways,
#[arg(skip)]
ZMuldefs,
#[arg(skip)]
ZKeepTextSectionPrefix,
#[arg(skip)]
ZNokeepTextSectionPrefix,
#[arg(skip)]
ZShstk,
#[arg(skip)]
ZText,
#[arg(skip)]
ZNotext,
#[arg(skip)]
ZTextoff,
#[arg(skip)]
ZOrigin,
#[arg(skip)]
ZNodefaultlib,
#[arg(skip)]
ZSeparateLoadableSegments,
#[arg(skip)]
ZSeparateCode,
#[arg(skip)]
ZNoseparateCode,
#[arg(skip)]
ZStackSize(OsString),
#[arg(skip)]
ZDynamicUndefinedWeak,
#[arg(skip)]
ZNodynamicUndefinedWeak,
#[arg(skip)]
ZSectionheader,
#[arg(skip)]
ZNosectionheader,
#[arg(skip)]
ZRodynamic,
#[arg(skip)]
ZX8664V2,
#[arg(skip)]
ZX8664V3,
#[arg(skip)]
ZX8664V4,
#[arg(skip)]
ZRewriteEndbr,
#[arg(skip)]
ZNorewriteEndbr,
#[arg(unknown)]
Unknown(OsString),
#[arg(bundle)]
Grouped(OsString),
#[arg(positional)]
Input(OsString),
}
fn z_opt(word: &OsStr) -> Option<Item> {
let word = word.to_str()?;
Some(match word {
"pack-relative-relocs" => Item::PackDynRelocs(OsString::from("relr")),
"nopack-relative-relocs" => Item::PackDynRelocs(OsString::from("none")),
"now" => Item::ZNow,
"lazy" => Item::ZLazy,
"cet-report=none" => Item::ZCetReportNone,
"cet-report=warning" => Item::ZCetReportWarning,
"cet-report=error" => Item::ZCetReportError,
"bti-report=none" => Item::ZBtiReportNone,
"bti-report=warning" => Item::ZBtiReportWarning,
"bti-report=error" => Item::ZBtiReportError,
"gcs-report=none" => Item::ZGcsReportNone,
"gcs-report=warning" => Item::ZGcsReportWarning,
"gcs-report=error" => Item::ZGcsReportError,
"execstack" => Item::ZExecstack,
"execstack-if-needed" => Item::ZExecstackIfNeeded,
"start-stop-visibility=protected" => Item::ZStartStopVisibilityProtected,
"start-stop-visibility=hidden" => Item::ZStartStopVisibilityHidden,
"noexecstack" => Item::ZNoexecstack,
"relro" => Item::ZRelro,
"norelro" => Item::ZNorelro,
"defs" => Item::NoUndefined,
"undefs" => Item::ZUndefs,
"nodlopen" => Item::ZNodlopen,
"nodelete" => Item::ZNodelete,
"nocopyreloc" => Item::ZNocopyreloc,
"nodump" => Item::ZNodump,
"initfirst" => Item::ZInitfirst,
"interpose" => Item::ZInterpose,
"ibt" => Item::ZIbt,
"ibtplt" => Item::ZIbtplt,
"force-bti" => Item::ZForceBti,
"pac-plt" => Item::ZPacPlt,
"gcs=implicit" => Item::ZGcsImplicit,
"gcs=never" => Item::ZGcsNever,
"gcs=always" => Item::ZGcsAlways,
"muldefs" => Item::ZMuldefs,
"keep-text-section-prefix" => Item::ZKeepTextSectionPrefix,
"nokeep-text-section-prefix" => Item::ZNokeepTextSectionPrefix,
"shstk" => Item::ZShstk,
"text" => Item::ZText,
"notext" => Item::ZNotext,
"textoff" => Item::ZTextoff,
"origin" => Item::ZOrigin,
"nodefaultlib" => Item::ZNodefaultlib,
"separate-loadable-segments" => Item::ZSeparateLoadableSegments,
"separate-code" => Item::ZSeparateCode,
"noseparate-code" => Item::ZNoseparateCode,
"dynamic-undefined-weak" => Item::ZDynamicUndefinedWeak,
"nodynamic-undefined-weak" => Item::ZNodynamicUndefinedWeak,
"sectionheader" => Item::ZSectionheader,
"nosectionheader" => Item::ZNosectionheader,
"rodynamic" => Item::ZRodynamic,
"x86-64-v2" => Item::ZX8664V2,
"x86-64-v3" => Item::ZX8664V3,
"x86-64-v4" => Item::ZX8664V4,
"rewrite-endbr" => Item::ZRewriteEndbr,
"norewrite-endbr" => Item::ZNorewriteEndbr,
"combreloc" => Item::IgnoredShortO(OsString::new()),
"nocombreloc" => Item::IgnoredShortO(OsString::new()),
_ => {
if let Some(value) = word.strip_prefix("max-page-size=") {
return Some(Item::ZMaxPageSize(OsString::from(value)));
}
if let Some(value) = word.strip_prefix("stack-size=") {
return Some(Item::ZStackSize(OsString::from(value)));
}
if let Some(value) = word.strip_prefix("common-page-size=") {
let _ = value;
return Some(Item::IgnoredShortO(OsString::new()));
}
return None;
}
})
}
fn main() {
let args: Vec<OsString> = std::env::args_os().skip(1).collect();
let mut files = ResponseFiles::default();
let words = match expand(&args, &mut files) {
Ok(words) => words,
Err(error) => {
eprintln!("error: {error}");
std::process::exit(2);
}
};
if let Some(n) = std::env::var("PARSE_N")
.ok()
.and_then(|n| n.parse::<usize>().ok())
{
for _ in 0..n {
let _ = std::hint::black_box(Cli::parse_words(std::hint::black_box(&words)));
}
return;
}
match Cli::parse_words(&words) {
Ok(cli) => {
for item in cli.items {
let item = match item {
Item::Z(z) => z_opt(&z.value).unwrap_or(Item::Z(z)),
item => item,
};
println!("{item:?}");
}
}
Err(error) => std::process::exit(winnow_args::report(&error, "ld")),
}
}