chore(vendor): add anyhow crate
This commit was merged in pull request #68.
This commit is contained in:
1
third_party/crates/clap_lex-1.1.1/.cargo-checksum.json
vendored
Normal file
1
third_party/crates/clap_lex-1.1.1/.cargo-checksum.json
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"3c66365ed8cb533ed286ac1a4d8e4bd65c414059bbe8d669ca48af4dc7e302b9","Cargo.lock":"ab6ff99e7aa380606a5177ad57d5cdcab689aebf3126b1ede42389f34d652b18","Cargo.toml":"0fba3575d7ecb08dd83b5b0020c017e8f774d19021fb922775675f66ae4c4874","Cargo.toml.orig":"622136d7e3e5fb5cdecb565ac51c0cdca747d5bd046b8b86d5f1a0d06306ab6b","LICENSE-APACHE":"249fdb6694467dd615b259f7ddde07be3f8ae5a72cecebb0e24f6629af4215fe","LICENSE-MIT":"6efb0476a1cc085077ed49357026d8c173bf33017278ef440f222fb9cbcb66e6","README.md":"32bf96a821edf229cb5d30e7b66cfc526ed70cde7f1690b7cb10b542449b6012","src/ext.rs":"2261786f7d085bb9b36af8b8629633d531b348300de826c0881a4385e9da127f","src/lib.rs":"5ea6362c3fe3f140c837446310cc83afe689d7460ecc8533760836b751ab1a83"},"package":"1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486"}
|
||||
6
third_party/crates/clap_lex-1.1.1/.cargo_vcs_info.json
vendored
Normal file
6
third_party/crates/clap_lex-1.1.1/.cargo_vcs_info.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"git": {
|
||||
"sha1": "13f2db5072d600c11d8d6298e4e9ba53ffc6c1ab"
|
||||
},
|
||||
"path_in_vcs": "clap_lex"
|
||||
}
|
||||
110
third_party/crates/clap_lex-1.1.1/BUILD.bazel
vendored
Normal file
110
third_party/crates/clap_lex-1.1.1/BUILD.bazel
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
###############################################################################
|
||||
# @generated
|
||||
# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To
|
||||
# regenerate this file, run the following:
|
||||
#
|
||||
# bazel run @@//third_party:vendor_crates
|
||||
###############################################################################
|
||||
|
||||
load("@rules_rust//cargo:defs.bzl", "cargo_toml_env_vars")
|
||||
load("@rules_rust//rust:defs.bzl", "rust_library")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
cargo_toml_env_vars(
|
||||
name = "cargo_toml_env_vars",
|
||||
src = "Cargo.toml",
|
||||
)
|
||||
|
||||
rust_library(
|
||||
name = "clap_lex",
|
||||
srcs = glob(
|
||||
include = ["**/*.rs"],
|
||||
allow_empty = False,
|
||||
),
|
||||
compile_data = glob(
|
||||
include = ["**"],
|
||||
allow_empty = True,
|
||||
exclude = [
|
||||
"**/* *",
|
||||
".tmp_git_root/**/*",
|
||||
"BUILD",
|
||||
"BUILD.bazel",
|
||||
"WORKSPACE",
|
||||
"WORKSPACE.bazel",
|
||||
],
|
||||
),
|
||||
crate_root = "src/lib.rs",
|
||||
edition = "2024",
|
||||
rustc_env_files = [
|
||||
":cargo_toml_env_vars",
|
||||
],
|
||||
rustc_flags = [
|
||||
"--cap-lints=allow",
|
||||
],
|
||||
tags = [
|
||||
"cargo-bazel",
|
||||
"crate-name=clap_lex",
|
||||
"manual",
|
||||
"noclippy",
|
||||
"norustfmt",
|
||||
],
|
||||
target_compatible_with = select({
|
||||
"@rules_rust//rust/platform:aarch64-apple-darwin": [],
|
||||
"@rules_rust//rust/platform:aarch64-apple-ios": [],
|
||||
"@rules_rust//rust/platform:aarch64-apple-ios-macabi": [],
|
||||
"@rules_rust//rust/platform:aarch64-apple-ios-sim": [],
|
||||
"@rules_rust//rust/platform:aarch64-linux-android": [],
|
||||
"@rules_rust//rust/platform:aarch64-pc-windows-msvc": [],
|
||||
"@rules_rust//rust/platform:aarch64-unknown-fuchsia": [],
|
||||
"@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [],
|
||||
"@rules_rust//rust/platform:aarch64-unknown-none": [],
|
||||
"@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [],
|
||||
"@rules_rust//rust/platform:aarch64-unknown-uefi": [],
|
||||
"@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [],
|
||||
"@rules_rust//rust/platform:arm-unknown-linux-musleabi": [],
|
||||
"@rules_rust//rust/platform:armv7-linux-androideabi": [],
|
||||
"@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [],
|
||||
"@rules_rust//rust/platform:i686-apple-darwin": [],
|
||||
"@rules_rust//rust/platform:i686-linux-android": [],
|
||||
"@rules_rust//rust/platform:i686-pc-windows-msvc": [],
|
||||
"@rules_rust//rust/platform:i686-unknown-freebsd": [],
|
||||
"@rules_rust//rust/platform:i686-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:loongarch64-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:mips-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:riscv32imac-unknown-none-elf": [],
|
||||
"@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [],
|
||||
"@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [],
|
||||
"@rules_rust//rust/platform:s390x-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:sparc64-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:sparc64-unknown-netbsd": [],
|
||||
"@rules_rust//rust/platform:sparc64-unknown-openbsd": [],
|
||||
"@rules_rust//rust/platform:thumbv6m-none-eabi": [],
|
||||
"@rules_rust//rust/platform:thumbv7em-none-eabi": [],
|
||||
"@rules_rust//rust/platform:thumbv7em-none-eabihf": [],
|
||||
"@rules_rust//rust/platform:thumbv7m-none-eabi": [],
|
||||
"@rules_rust//rust/platform:thumbv8m.main-none-eabi": [],
|
||||
"@rules_rust//rust/platform:thumbv8m.main-none-eabihf": [],
|
||||
"@rules_rust//rust/platform:wasm32-unknown-emscripten": [],
|
||||
"@rules_rust//rust/platform:wasm32-unknown-unknown": [],
|
||||
"@rules_rust//rust/platform:wasm32-wasip1": [],
|
||||
"@rules_rust//rust/platform:wasm32-wasip1-threads": [],
|
||||
"@rules_rust//rust/platform:wasm32-wasip2": [],
|
||||
"@rules_rust//rust/platform:x86_64-apple-darwin": [],
|
||||
"@rules_rust//rust/platform:x86_64-apple-ios": [],
|
||||
"@rules_rust//rust/platform:x86_64-apple-ios-macabi": [],
|
||||
"@rules_rust//rust/platform:x86_64-linux-android": [],
|
||||
"@rules_rust//rust/platform:x86_64-pc-windows-msvc": [],
|
||||
"@rules_rust//rust/platform:x86_64-unknown-freebsd": [],
|
||||
"@rules_rust//rust/platform:x86_64-unknown-fuchsia": [],
|
||||
"@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [],
|
||||
"@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [],
|
||||
"@rules_rust//rust/platform:x86_64-unknown-none": [],
|
||||
"@rules_rust//rust/platform:x86_64-unknown-uefi": [],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
}),
|
||||
version = "1.1.1",
|
||||
)
|
||||
56
third_party/crates/clap_lex-1.1.1/Cargo.lock
generated
vendored
Normal file
56
third_party/crates/clap_lex-1.1.1/Cargo.lock
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "automod"
|
||||
version = "1.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a273e731a7fb8c2268fd2932c9e9a3469f4fd171d85d070d2687190229653bd3"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "1.1.1"
|
||||
dependencies = [
|
||||
"automod",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.119"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||
179
third_party/crates/clap_lex-1.1.1/Cargo.toml
vendored
Normal file
179
third_party/crates/clap_lex-1.1.1/Cargo.toml
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
edition = "2024"
|
||||
rust-version = "1.85"
|
||||
name = "clap_lex"
|
||||
version = "1.1.1"
|
||||
build = false
|
||||
include = [
|
||||
"/build.rs",
|
||||
"/src/**/*",
|
||||
"/Cargo.toml",
|
||||
"/Cargo.lock",
|
||||
"/LICENSE*",
|
||||
"/README.md",
|
||||
"/examples/**/*",
|
||||
]
|
||||
autolib = false
|
||||
autobins = false
|
||||
autoexamples = false
|
||||
autotests = false
|
||||
autobenches = false
|
||||
description = "Minimal, flexible command line parser"
|
||||
readme = "README.md"
|
||||
keywords = [
|
||||
"argument",
|
||||
"cli",
|
||||
"arg",
|
||||
"parser",
|
||||
"parse",
|
||||
]
|
||||
categories = ["command-line-interface"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/clap-rs/clap"
|
||||
resolver = "2"
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "CHANGELOG.md"
|
||||
search = "Unreleased"
|
||||
replace = "{{version}}"
|
||||
min = 1
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "CHANGELOG.md"
|
||||
search = '\.\.\.HEAD'
|
||||
replace = "...{{tag_name}}"
|
||||
exactly = 1
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "CHANGELOG.md"
|
||||
search = "ReleaseDate"
|
||||
replace = "{{date}}"
|
||||
min = 1
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "CHANGELOG.md"
|
||||
search = "<!-- next-header -->"
|
||||
replace = """
|
||||
<!-- next-header -->
|
||||
## [Unreleased] - ReleaseDate
|
||||
"""
|
||||
exactly = 1
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "CHANGELOG.md"
|
||||
search = "<!-- next-url -->"
|
||||
replace = """
|
||||
<!-- next-url -->
|
||||
[Unreleased]: https://github.com/clap-rs/clap/compare/{{tag_name}}...HEAD"""
|
||||
exactly = 1
|
||||
|
||||
[[package.metadata.release.pre-release-replacements]]
|
||||
file = "README.md"
|
||||
search = "github.com/clap-rs/clap/blob/[^/]+/"
|
||||
replace = "github.com/clap-rs/clap/blob/{{tag_name}}/"
|
||||
exactly = 4
|
||||
prerelease = true
|
||||
|
||||
[lib]
|
||||
name = "clap_lex"
|
||||
path = "src/lib.rs"
|
||||
bench = false
|
||||
|
||||
[dev-dependencies.automod]
|
||||
version = "1.0.16"
|
||||
|
||||
[lints.clippy]
|
||||
assigning_clones = "allow"
|
||||
blocks_in_conditions = "allow"
|
||||
bool_assert_comparison = "allow"
|
||||
branches_sharing_code = "allow"
|
||||
byte_char_slices = "allow"
|
||||
checked_conversions = "warn"
|
||||
collapsible_else_if = "allow"
|
||||
collapsible_match = "allow"
|
||||
collection_is_never_read = "warn"
|
||||
create_dir = "warn"
|
||||
dbg_macro = "warn"
|
||||
debug_assert_with_mut_call = "warn"
|
||||
doc_markdown = "warn"
|
||||
empty_enums = "warn"
|
||||
enum_glob_use = "warn"
|
||||
expl_impl_clone_on_copy = "warn"
|
||||
explicit_deref_methods = "warn"
|
||||
explicit_into_iter_loop = "warn"
|
||||
fallible_impl_from = "warn"
|
||||
filter_map_next = "warn"
|
||||
flat_map_option = "warn"
|
||||
float_cmp = "warn"
|
||||
float_cmp_const = "warn"
|
||||
fn_params_excessive_bools = "warn"
|
||||
fn_to_numeric_cast_any = "warn"
|
||||
if_same_then_else = "allow"
|
||||
implicit_clone = "warn"
|
||||
imprecise_flops = "warn"
|
||||
inconsistent_struct_constructor = "warn"
|
||||
inefficient_to_string = "warn"
|
||||
infinite_loop = "warn"
|
||||
invalid_upcast_comparisons = "warn"
|
||||
large_digit_groups = "warn"
|
||||
large_stack_arrays = "warn"
|
||||
large_types_passed_by_value = "warn"
|
||||
let_and_return = "allow"
|
||||
linkedlist = "warn"
|
||||
lossy_float_literal = "warn"
|
||||
macro_use_imports = "warn"
|
||||
mem_forget = "warn"
|
||||
mismatching_type_param_order = "warn"
|
||||
multiple_bound_locations = "allow"
|
||||
mutex_integer = "warn"
|
||||
needless_continue = "allow"
|
||||
needless_for_each = "warn"
|
||||
negative_feature_names = "warn"
|
||||
partial_pub_fields = "warn"
|
||||
path_buf_push_overwrite = "warn"
|
||||
ptr_as_ptr = "warn"
|
||||
rc_mutex = "warn"
|
||||
redundant_feature_names = "warn"
|
||||
ref_option_ref = "warn"
|
||||
rest_pat_in_fully_bound_structs = "warn"
|
||||
result_large_err = "allow"
|
||||
same_functions_in_if_condition = "warn"
|
||||
self_named_module_files = "warn"
|
||||
semicolon_if_nothing_returned = "warn"
|
||||
str_to_string = "warn"
|
||||
string_add = "warn"
|
||||
string_add_assign = "warn"
|
||||
string_lit_as_bytes = "warn"
|
||||
todo = "warn"
|
||||
trait_duplication_in_bounds = "warn"
|
||||
uninlined_format_args = "warn"
|
||||
unnecessary_safety_comment = "warn"
|
||||
unnecessary_safety_doc = "warn"
|
||||
unseparated_literal_suffix = "warn"
|
||||
use_self = "warn"
|
||||
verbose_file_reads = "warn"
|
||||
zero_sized_map_values = "warn"
|
||||
|
||||
[lints.rust]
|
||||
non_ascii_idents = "warn"
|
||||
trivial_numeric_casts = "warn"
|
||||
unreachable_pub = "warn"
|
||||
unsafe_op_in_unsafe_fn = "warn"
|
||||
unused_lifetimes = "warn"
|
||||
unused_macro_rules = "warn"
|
||||
unused_qualifications = "warn"
|
||||
|
||||
[lints.rust.rust_2018_idioms]
|
||||
level = "warn"
|
||||
priority = -1
|
||||
36
third_party/crates/clap_lex-1.1.1/Cargo.toml.orig
generated
vendored
Normal file
36
third_party/crates/clap_lex-1.1.1/Cargo.toml.orig
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
[package]
|
||||
name = "clap_lex"
|
||||
version = "1.1.1"
|
||||
description = "Minimal, flexible command line parser"
|
||||
categories = ["command-line-interface"]
|
||||
keywords = [
|
||||
"argument",
|
||||
"cli",
|
||||
"arg",
|
||||
"parser",
|
||||
"parse"
|
||||
]
|
||||
repository.workspace = true
|
||||
license.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
include.workspace = true
|
||||
|
||||
[package.metadata.release]
|
||||
pre-release-replacements = [
|
||||
{file="CHANGELOG.md", search="Unreleased", replace="{{version}}", min=1},
|
||||
{file="CHANGELOG.md", search="\\.\\.\\.HEAD", replace="...{{tag_name}}", exactly=1},
|
||||
{file="CHANGELOG.md", search="ReleaseDate", replace="{{date}}", min=1},
|
||||
{file="CHANGELOG.md", search="<!-- next-header -->", replace="<!-- next-header -->\n## [Unreleased] - ReleaseDate\n", exactly=1},
|
||||
{file="CHANGELOG.md", search="<!-- next-url -->", replace="<!-- next-url -->\n[Unreleased]: https://github.com/clap-rs/clap/compare/{{tag_name}}...HEAD", exactly=1},
|
||||
{file="README.md", search="github.com/clap-rs/clap/blob/[^/]+/", replace="github.com/clap-rs/clap/blob/{{tag_name}}/", exactly=4, prerelease = true},
|
||||
]
|
||||
|
||||
[dev-dependencies]
|
||||
automod = "1.0.16"
|
||||
|
||||
[lib]
|
||||
bench = false
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
202
third_party/crates/clap_lex-1.1.1/LICENSE-APACHE
vendored
Normal file
202
third_party/crates/clap_lex-1.1.1/LICENSE-APACHE
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright Individual contributors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
19
third_party/crates/clap_lex-1.1.1/LICENSE-MIT
vendored
Normal file
19
third_party/crates/clap_lex-1.1.1/LICENSE-MIT
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) Individual contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
19
third_party/crates/clap_lex-1.1.1/README.md
vendored
Normal file
19
third_party/crates/clap_lex-1.1.1/README.md
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<!-- omit in TOC -->
|
||||
# clap_lex
|
||||
|
||||
> **Minimal, flexible command line parser**
|
||||
|
||||
[](https://crates.io/crates/clap_lex)
|
||||
[](https://crates.io/crates/clap_lex)
|
||||
[](https://github.com/clap-rs/clap/blob/clap_lex-v1.1.1/LICENSE-APACHE)
|
||||
[](https://github.com/clap-rs/clap/blob/clap_lex-v1.1.1/LICENSE-MIT)
|
||||
|
||||
Dual-licensed under [Apache 2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT).
|
||||
|
||||
1. [About](#about)
|
||||
2. [API Reference](https://docs.rs/clap_lex)
|
||||
3. [Questions & Discussions](https://github.com/clap-rs/clap/discussions)
|
||||
4. [CONTRIBUTING](https://github.com/clap-rs/clap/blob/clap_lex-v1.1.1/clap_lex/CONTRIBUTING.md)
|
||||
5. [Sponsors](https://github.com/clap-rs/clap/blob/clap_lex-v1.1.1/README.md#sponsors)
|
||||
|
||||
## About
|
||||
284
third_party/crates/clap_lex-1.1.1/src/ext.rs
vendored
Normal file
284
third_party/crates/clap_lex-1.1.1/src/ext.rs
vendored
Normal file
@@ -0,0 +1,284 @@
|
||||
use std::ffi::OsStr;
|
||||
|
||||
/// String-like methods for [`OsStr`]
|
||||
pub trait OsStrExt: private::Sealed {
|
||||
/// Converts to a string slice.
|
||||
///
|
||||
/// The `Utf8Error` is guaranteed to have a valid UTF8 boundary
|
||||
/// in its `valid_up_to()`
|
||||
fn try_str(&self) -> Result<&str, std::str::Utf8Error>;
|
||||
/// Returns `true` if the given pattern matches a sub-slice of
|
||||
/// this string slice.
|
||||
///
|
||||
/// Returns `false` if it does not.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use clap_lex::OsStrExt as _;
|
||||
/// let bananas = std::ffi::OsStr::new("bananas");
|
||||
///
|
||||
/// assert!(bananas.contains("nana"));
|
||||
/// assert!(!bananas.contains("apples"));
|
||||
/// ```
|
||||
fn contains(&self, needle: &str) -> bool;
|
||||
/// Returns the byte index of the first character of this string slice that
|
||||
/// matches the pattern.
|
||||
///
|
||||
/// Returns [`None`] if the pattern doesn't match.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use clap_lex::OsStrExt as _;
|
||||
/// let s = std::ffi::OsStr::new("Löwe 老虎 Léopard Gepardi");
|
||||
///
|
||||
/// assert_eq!(s.find("L"), Some(0));
|
||||
/// assert_eq!(s.find("é"), Some(14));
|
||||
/// assert_eq!(s.find("par"), Some(17));
|
||||
/// ```
|
||||
///
|
||||
/// Not finding the pattern:
|
||||
///
|
||||
/// ```rust
|
||||
/// use clap_lex::OsStrExt as _;
|
||||
/// let s = std::ffi::OsStr::new("Löwe 老虎 Léopard");
|
||||
///
|
||||
/// assert_eq!(s.find("1"), None);
|
||||
/// ```
|
||||
fn find(&self, needle: &str) -> Option<usize>;
|
||||
/// Returns a string slice with the prefix removed.
|
||||
///
|
||||
/// If the string starts with the pattern `prefix`, returns substring after the prefix, wrapped
|
||||
/// in `Some`.
|
||||
///
|
||||
/// If the string does not start with `prefix`, returns `None`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::ffi::OsStr;
|
||||
/// use clap_lex::OsStrExt as _;
|
||||
/// assert_eq!(OsStr::new("foo:bar").strip_prefix("foo:"), Some(OsStr::new("bar")));
|
||||
/// assert_eq!(OsStr::new("foo:bar").strip_prefix("bar"), None);
|
||||
/// assert_eq!(OsStr::new("foofoo").strip_prefix("foo"), Some(OsStr::new("foo")));
|
||||
/// ```
|
||||
fn strip_prefix(&self, prefix: &str) -> Option<&OsStr>;
|
||||
/// Returns `true` if the given pattern matches a prefix of this
|
||||
/// string slice.
|
||||
///
|
||||
/// Returns `false` if it does not.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use clap_lex::OsStrExt as _;
|
||||
/// let bananas = std::ffi::OsStr::new("bananas");
|
||||
///
|
||||
/// assert!(bananas.starts_with("bana"));
|
||||
/// assert!(!bananas.starts_with("nana"));
|
||||
/// ```
|
||||
fn starts_with(&self, prefix: &str) -> bool;
|
||||
/// An iterator over substrings of this string slice, separated by
|
||||
/// characters matched by a pattern.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Simple patterns:
|
||||
///
|
||||
/// ```
|
||||
/// use std::ffi::OsStr;
|
||||
/// use clap_lex::OsStrExt as _;
|
||||
/// let v: Vec<_> = OsStr::new("Mary had a little lamb").split(" ").collect();
|
||||
/// assert_eq!(v, [OsStr::new("Mary"), OsStr::new("had"), OsStr::new("a"), OsStr::new("little"), OsStr::new("lamb")]);
|
||||
///
|
||||
/// let v: Vec<_> = OsStr::new("").split("X").collect();
|
||||
/// assert_eq!(v, [OsStr::new("")]);
|
||||
///
|
||||
/// let v: Vec<_> = OsStr::new("lionXXtigerXleopard").split("X").collect();
|
||||
/// assert_eq!(v, [OsStr::new("lion"), OsStr::new(""), OsStr::new("tiger"), OsStr::new("leopard")]);
|
||||
///
|
||||
/// let v: Vec<_> = OsStr::new("lion::tiger::leopard").split("::").collect();
|
||||
/// assert_eq!(v, [OsStr::new("lion"), OsStr::new("tiger"), OsStr::new("leopard")]);
|
||||
/// ```
|
||||
///
|
||||
/// If a string contains multiple contiguous separators, you will end up
|
||||
/// with empty strings in the output:
|
||||
///
|
||||
/// ```
|
||||
/// use std::ffi::OsStr;
|
||||
/// use clap_lex::OsStrExt as _;
|
||||
/// let x = OsStr::new("||||a||b|c");
|
||||
/// let d: Vec<_> = x.split("|").collect();
|
||||
///
|
||||
/// assert_eq!(d, &[OsStr::new(""), OsStr::new(""), OsStr::new(""), OsStr::new(""), OsStr::new("a"), OsStr::new(""), OsStr::new("b"), OsStr::new("c")]);
|
||||
/// ```
|
||||
///
|
||||
/// Contiguous separators are separated by the empty string.
|
||||
///
|
||||
/// ```
|
||||
/// use std::ffi::OsStr;
|
||||
/// use clap_lex::OsStrExt as _;
|
||||
/// let x = OsStr::new("(///)");
|
||||
/// let d: Vec<_> = x.split("/").collect();
|
||||
///
|
||||
/// assert_eq!(d, &[OsStr::new("("), OsStr::new(""), OsStr::new(""), OsStr::new(")")]);
|
||||
/// ```
|
||||
///
|
||||
/// Separators at the start or end of a string are neighbored
|
||||
/// by empty strings.
|
||||
///
|
||||
/// ```
|
||||
/// use std::ffi::OsStr;
|
||||
/// use clap_lex::OsStrExt as _;
|
||||
/// let d: Vec<_> = OsStr::new("010").split("0").collect();
|
||||
/// assert_eq!(d, &[OsStr::new(""), OsStr::new("1"), OsStr::new("")]);
|
||||
/// ```
|
||||
///
|
||||
/// When the empty string is used as a separator, it panics
|
||||
///
|
||||
/// ```should_panic
|
||||
/// use std::ffi::OsStr;
|
||||
/// use clap_lex::OsStrExt as _;
|
||||
/// let f: Vec<_> = OsStr::new("rust").split("").collect();
|
||||
/// assert_eq!(f, &[OsStr::new(""), OsStr::new("r"), OsStr::new("u"), OsStr::new("s"), OsStr::new("t"), OsStr::new("")]);
|
||||
/// ```
|
||||
///
|
||||
/// Contiguous separators can lead to possibly surprising behavior
|
||||
/// when whitespace is used as the separator. This code is correct:
|
||||
///
|
||||
/// ```
|
||||
/// use std::ffi::OsStr;
|
||||
/// use clap_lex::OsStrExt as _;
|
||||
/// let x = OsStr::new(" a b c");
|
||||
/// let d: Vec<_> = x.split(" ").collect();
|
||||
///
|
||||
/// assert_eq!(d, &[OsStr::new(""), OsStr::new(""), OsStr::new(""), OsStr::new(""), OsStr::new("a"), OsStr::new(""), OsStr::new("b"), OsStr::new("c")]);
|
||||
/// ```
|
||||
///
|
||||
/// It does _not_ give you:
|
||||
///
|
||||
/// ```,ignore
|
||||
/// assert_eq!(d, &[OsStr::new("a"), OsStr::new("b"), OsStr::new("c")]);
|
||||
/// ```
|
||||
///
|
||||
/// Use [`split_whitespace`] for this behavior.
|
||||
///
|
||||
/// [`split_whitespace`]: str::split_whitespace
|
||||
fn split<'s, 'n>(&'s self, needle: &'n str) -> Split<'s, 'n>;
|
||||
/// Splits the string on the first occurrence of the specified delimiter and
|
||||
/// returns prefix before delimiter and suffix after delimiter.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::ffi::OsStr;
|
||||
/// use clap_lex::OsStrExt as _;
|
||||
/// assert_eq!(OsStr::new("cfg").split_once("="), None);
|
||||
/// assert_eq!(OsStr::new("cfg=").split_once("="), Some((OsStr::new("cfg"), OsStr::new(""))));
|
||||
/// assert_eq!(OsStr::new("cfg=foo").split_once("="), Some((OsStr::new("cfg"), OsStr::new("foo"))));
|
||||
/// assert_eq!(OsStr::new("cfg=foo=bar").split_once("="), Some((OsStr::new("cfg"), OsStr::new("foo=bar"))));
|
||||
/// ```
|
||||
fn split_once(&self, needle: &'_ str) -> Option<(&OsStr, &OsStr)>;
|
||||
}
|
||||
|
||||
impl OsStrExt for OsStr {
|
||||
fn try_str(&self) -> Result<&str, std::str::Utf8Error> {
|
||||
let bytes = self.as_encoded_bytes();
|
||||
std::str::from_utf8(bytes)
|
||||
}
|
||||
|
||||
fn contains(&self, needle: &str) -> bool {
|
||||
self.find(needle).is_some()
|
||||
}
|
||||
|
||||
fn find(&self, needle: &str) -> Option<usize> {
|
||||
let bytes = self.as_encoded_bytes();
|
||||
(0..=self.len().checked_sub(needle.len())?)
|
||||
.find(|&x| bytes[x..].starts_with(needle.as_bytes()))
|
||||
}
|
||||
|
||||
fn strip_prefix(&self, prefix: &str) -> Option<&OsStr> {
|
||||
let bytes = self.as_encoded_bytes();
|
||||
bytes.strip_prefix(prefix.as_bytes()).map(|s| {
|
||||
// SAFETY:
|
||||
// - This came from `as_encoded_bytes`
|
||||
// - Since `prefix` is `&str`, any split will be along UTF-8 boundary
|
||||
unsafe { Self::from_encoded_bytes_unchecked(s) }
|
||||
})
|
||||
}
|
||||
fn starts_with(&self, prefix: &str) -> bool {
|
||||
let bytes = self.as_encoded_bytes();
|
||||
bytes.starts_with(prefix.as_bytes())
|
||||
}
|
||||
|
||||
fn split<'s, 'n>(&'s self, needle: &'n str) -> Split<'s, 'n> {
|
||||
assert_ne!(needle, "");
|
||||
Split {
|
||||
haystack: Some(self),
|
||||
needle,
|
||||
}
|
||||
}
|
||||
|
||||
fn split_once(&self, needle: &'_ str) -> Option<(&OsStr, &OsStr)> {
|
||||
let start = self.find(needle)?;
|
||||
let end = start + needle.len();
|
||||
let haystack = self.as_encoded_bytes();
|
||||
let first = &haystack[0..start];
|
||||
let second = &haystack[end..];
|
||||
// SAFETY:
|
||||
// - This came from `as_encoded_bytes`
|
||||
// - Since `needle` is `&str`, any split will be along UTF-8 boundary
|
||||
unsafe {
|
||||
Some((
|
||||
Self::from_encoded_bytes_unchecked(first),
|
||||
Self::from_encoded_bytes_unchecked(second),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod private {
|
||||
pub trait Sealed {}
|
||||
|
||||
impl Sealed for std::ffi::OsStr {}
|
||||
}
|
||||
|
||||
pub struct Split<'s, 'n> {
|
||||
haystack: Option<&'s OsStr>,
|
||||
needle: &'n str,
|
||||
}
|
||||
|
||||
impl<'s> Iterator for Split<'s, '_> {
|
||||
type Item = &'s OsStr;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let haystack = self.haystack?;
|
||||
if let Some((first, second)) = haystack.split_once(self.needle) {
|
||||
if !haystack.is_empty() {
|
||||
debug_assert_ne!(haystack, second);
|
||||
}
|
||||
self.haystack = Some(second);
|
||||
Some(first)
|
||||
} else {
|
||||
self.haystack = None;
|
||||
Some(haystack)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Split an `OsStr`
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// `index` must be at a valid UTF-8 boundary
|
||||
pub(crate) unsafe fn split_at(os: &OsStr, index: usize) -> (&OsStr, &OsStr) {
|
||||
unsafe {
|
||||
let bytes = os.as_encoded_bytes();
|
||||
let (first, second) = bytes.split_at(index);
|
||||
(
|
||||
OsStr::from_encoded_bytes_unchecked(first),
|
||||
OsStr::from_encoded_bytes_unchecked(second),
|
||||
)
|
||||
}
|
||||
}
|
||||
526
third_party/crates/clap_lex-1.1.1/src/lib.rs
vendored
Normal file
526
third_party/crates/clap_lex-1.1.1/src/lib.rs
vendored
Normal file
@@ -0,0 +1,526 @@
|
||||
//! Minimal, flexible command-line parser
|
||||
//!
|
||||
//! As opposed to a declarative parser, this processes arguments as a stream of tokens. As lexing
|
||||
//! a command-line is not context-free, we rely on the caller to decide how to interpret the
|
||||
//! arguments.
|
||||
//!
|
||||
//! # Examples
|
||||
//!
|
||||
//! ```rust
|
||||
//! use std::path::PathBuf;
|
||||
//! use std::ffi::OsStr;
|
||||
//!
|
||||
//! type BoxedError = Box<dyn std::error::Error + Send + Sync>;
|
||||
//!
|
||||
//! #[derive(Debug)]
|
||||
//! struct Args {
|
||||
//! paths: Vec<PathBuf>,
|
||||
//! color: Color,
|
||||
//! verbosity: usize,
|
||||
//! }
|
||||
//!
|
||||
//! #[derive(Debug)]
|
||||
//! enum Color {
|
||||
//! Always,
|
||||
//! Auto,
|
||||
//! Never,
|
||||
//! }
|
||||
//!
|
||||
//! impl Color {
|
||||
//! fn parse(s: Option<&OsStr>) -> Result<Self, BoxedError> {
|
||||
//! let s = s.map(|s| s.to_str().ok_or(s));
|
||||
//! match s {
|
||||
//! Some(Ok("always")) | Some(Ok("")) | None => {
|
||||
//! Ok(Color::Always)
|
||||
//! }
|
||||
//! Some(Ok("auto")) => {
|
||||
//! Ok(Color::Auto)
|
||||
//! }
|
||||
//! Some(Ok("never")) => {
|
||||
//! Ok(Color::Never)
|
||||
//! }
|
||||
//! Some(invalid) => {
|
||||
//! Err(format!("Invalid value for `--color`, {invalid:?}").into())
|
||||
//! }
|
||||
//! }
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! fn parse_args(
|
||||
//! raw: impl IntoIterator<Item=impl Into<std::ffi::OsString>>
|
||||
//! ) -> Result<Args, BoxedError> {
|
||||
//! let mut args = Args {
|
||||
//! paths: Vec::new(),
|
||||
//! color: Color::Auto,
|
||||
//! verbosity: 0,
|
||||
//! };
|
||||
//!
|
||||
//! let raw = clap_lex::RawArgs::new(raw);
|
||||
//! let mut cursor = raw.cursor();
|
||||
//! raw.next(&mut cursor); // Skip the bin
|
||||
//! while let Some(arg) = raw.next(&mut cursor) {
|
||||
//! if arg.is_escape() {
|
||||
//! args.paths.extend(raw.remaining(&mut cursor).map(PathBuf::from));
|
||||
//! } else if arg.is_stdio() {
|
||||
//! args.paths.push(PathBuf::from("-"));
|
||||
//! } else if let Some((long, value)) = arg.to_long() {
|
||||
//! match long {
|
||||
//! Ok("verbose") => {
|
||||
//! if let Some(value) = value {
|
||||
//! return Err(format!("`--verbose` does not take a value, got `{value:?}`").into());
|
||||
//! }
|
||||
//! args.verbosity += 1;
|
||||
//! }
|
||||
//! Ok("color") => {
|
||||
//! args.color = Color::parse(value)?;
|
||||
//! }
|
||||
//! _ => {
|
||||
//! return Err(
|
||||
//! format!("Unexpected flag: --{}", arg.display()).into()
|
||||
//! );
|
||||
//! }
|
||||
//! }
|
||||
//! } else if let Some(mut shorts) = arg.to_short() {
|
||||
//! while let Some(short) = shorts.next_flag() {
|
||||
//! match short {
|
||||
//! Ok('v') => {
|
||||
//! args.verbosity += 1;
|
||||
//! }
|
||||
//! Ok('c') => {
|
||||
//! let value = shorts.next_value_os();
|
||||
//! args.color = Color::parse(value)?;
|
||||
//! }
|
||||
//! Ok(c) => {
|
||||
//! return Err(format!("Unexpected flag: -{c}").into());
|
||||
//! }
|
||||
//! Err(e) => {
|
||||
//! return Err(format!("Unexpected flag: -{}", e.to_string_lossy()).into());
|
||||
//! }
|
||||
//! }
|
||||
//! }
|
||||
//! } else {
|
||||
//! args.paths.push(PathBuf::from(arg.to_value_os().to_owned()));
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! Ok(args)
|
||||
//! }
|
||||
//!
|
||||
//! let args = parse_args(["bin", "--hello", "world"]);
|
||||
//! println!("{args:?}");
|
||||
//! ```
|
||||
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
#![warn(missing_docs)]
|
||||
#![warn(clippy::print_stderr)]
|
||||
#![warn(clippy::print_stdout)]
|
||||
|
||||
mod ext;
|
||||
|
||||
use std::ffi::OsStr;
|
||||
use std::ffi::OsString;
|
||||
|
||||
pub use std::io::SeekFrom;
|
||||
|
||||
pub use ext::OsStrExt;
|
||||
|
||||
/// Command-line arguments
|
||||
#[derive(Default, Clone, Debug, PartialEq, Eq)]
|
||||
pub struct RawArgs {
|
||||
items: Vec<OsString>,
|
||||
}
|
||||
|
||||
impl RawArgs {
|
||||
//// Create an argument list to parse
|
||||
///
|
||||
/// <div class="warning">
|
||||
///
|
||||
/// **NOTE:** The argument returned will be the current binary.
|
||||
///
|
||||
/// </div>
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use std::path::PathBuf;
|
||||
/// let raw = clap_lex::RawArgs::from_args();
|
||||
/// let mut cursor = raw.cursor();
|
||||
/// let _bin = raw.next_os(&mut cursor);
|
||||
///
|
||||
/// let mut paths = raw.remaining(&mut cursor).map(PathBuf::from).collect::<Vec<_>>();
|
||||
/// println!("{paths:?}");
|
||||
/// ```
|
||||
pub fn from_args() -> Self {
|
||||
Self::new(std::env::args_os())
|
||||
}
|
||||
|
||||
//// Create an argument list to parse
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use std::path::PathBuf;
|
||||
/// let raw = clap_lex::RawArgs::new(["bin", "foo.txt"]);
|
||||
/// let mut cursor = raw.cursor();
|
||||
/// let _bin = raw.next_os(&mut cursor);
|
||||
///
|
||||
/// let mut paths = raw.remaining(&mut cursor).map(PathBuf::from).collect::<Vec<_>>();
|
||||
/// println!("{paths:?}");
|
||||
/// ```
|
||||
pub fn new(iter: impl IntoIterator<Item = impl Into<OsString>>) -> Self {
|
||||
let iter = iter.into_iter();
|
||||
Self::from(iter)
|
||||
}
|
||||
|
||||
/// Create a cursor for walking the arguments
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use std::path::PathBuf;
|
||||
/// let raw = clap_lex::RawArgs::new(["bin", "foo.txt"]);
|
||||
/// let mut cursor = raw.cursor();
|
||||
/// let _bin = raw.next_os(&mut cursor);
|
||||
///
|
||||
/// let mut paths = raw.remaining(&mut cursor).map(PathBuf::from).collect::<Vec<_>>();
|
||||
/// println!("{paths:?}");
|
||||
/// ```
|
||||
pub fn cursor(&self) -> ArgCursor {
|
||||
ArgCursor::new()
|
||||
}
|
||||
|
||||
/// Advance the cursor, returning the next [`ParsedArg`]
|
||||
pub fn next<'s>(&'s self, cursor: &mut ArgCursor) -> Option<ParsedArg<'s>> {
|
||||
self.next_os(cursor).map(ParsedArg::new)
|
||||
}
|
||||
|
||||
/// Advance the cursor, returning a raw argument value.
|
||||
pub fn next_os<'s>(&'s self, cursor: &mut ArgCursor) -> Option<&'s OsStr> {
|
||||
let next = self.items.get(cursor.cursor).map(|s| s.as_os_str());
|
||||
cursor.cursor = cursor.cursor.saturating_add(1);
|
||||
next
|
||||
}
|
||||
|
||||
/// Return the next [`ParsedArg`]
|
||||
pub fn peek<'s>(&'s self, cursor: &ArgCursor) -> Option<ParsedArg<'s>> {
|
||||
self.peek_os(cursor).map(ParsedArg::new)
|
||||
}
|
||||
|
||||
/// Return a raw argument value.
|
||||
pub fn peek_os<'s>(&'s self, cursor: &ArgCursor) -> Option<&'s OsStr> {
|
||||
self.items.get(cursor.cursor).map(|s| s.as_os_str())
|
||||
}
|
||||
|
||||
/// Return all remaining raw arguments, advancing the cursor to the end
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use std::path::PathBuf;
|
||||
/// let raw = clap_lex::RawArgs::new(["bin", "foo.txt"]);
|
||||
/// let mut cursor = raw.cursor();
|
||||
/// let _bin = raw.next_os(&mut cursor);
|
||||
///
|
||||
/// let mut paths = raw.remaining(&mut cursor).map(PathBuf::from).collect::<Vec<_>>();
|
||||
/// println!("{paths:?}");
|
||||
/// ```
|
||||
pub fn remaining<'s>(&'s self, cursor: &mut ArgCursor) -> impl Iterator<Item = &'s OsStr> {
|
||||
let remaining = self.items[cursor.cursor..].iter().map(|s| s.as_os_str());
|
||||
cursor.cursor = self.items.len();
|
||||
remaining
|
||||
}
|
||||
|
||||
/// Adjust the cursor's position
|
||||
pub fn seek(&self, cursor: &mut ArgCursor, pos: SeekFrom) {
|
||||
let pos = match pos {
|
||||
SeekFrom::Start(pos) => pos,
|
||||
SeekFrom::End(pos) => (self.items.len() as i64).saturating_add(pos).max(0) as u64,
|
||||
SeekFrom::Current(pos) => (cursor.cursor as i64).saturating_add(pos).max(0) as u64,
|
||||
};
|
||||
let pos = (pos as usize).min(self.items.len());
|
||||
cursor.cursor = pos;
|
||||
}
|
||||
|
||||
/// Inject arguments before the [`RawArgs::next`]
|
||||
pub fn insert(
|
||||
&mut self,
|
||||
cursor: &ArgCursor,
|
||||
insert_items: impl IntoIterator<Item = impl Into<OsString>>,
|
||||
) {
|
||||
self.items.splice(
|
||||
cursor.cursor..cursor.cursor,
|
||||
insert_items.into_iter().map(Into::into),
|
||||
);
|
||||
}
|
||||
|
||||
/// Any remaining args?
|
||||
pub fn is_end(&self, cursor: &ArgCursor) -> bool {
|
||||
self.peek_os(cursor).is_none()
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, T> From<I> for RawArgs
|
||||
where
|
||||
I: Iterator<Item = T>,
|
||||
T: Into<OsString>,
|
||||
{
|
||||
fn from(val: I) -> Self {
|
||||
Self {
|
||||
items: val.map(|x| x.into()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Position within [`RawArgs`]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct ArgCursor {
|
||||
cursor: usize,
|
||||
}
|
||||
|
||||
impl ArgCursor {
|
||||
fn new() -> Self {
|
||||
Self { cursor: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
/// Command-line Argument
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct ParsedArg<'s> {
|
||||
inner: &'s OsStr,
|
||||
}
|
||||
|
||||
impl<'s> ParsedArg<'s> {
|
||||
fn new(inner: &'s OsStr) -> Self {
|
||||
Self { inner }
|
||||
}
|
||||
|
||||
/// Argument is length of 0
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.inner.is_empty()
|
||||
}
|
||||
|
||||
/// Does the argument look like a stdio argument (`-`)
|
||||
pub fn is_stdio(&self) -> bool {
|
||||
self.inner == "-"
|
||||
}
|
||||
|
||||
/// Does the argument look like an argument escape (`--`)
|
||||
pub fn is_escape(&self) -> bool {
|
||||
self.inner == "--"
|
||||
}
|
||||
|
||||
/// Does the argument look like a negative number?
|
||||
///
|
||||
/// This won't parse the number in full but attempts to see if this looks
|
||||
/// like something along the lines of `-3`, `-0.3`, or `-33.03`
|
||||
pub fn is_negative_number(&self) -> bool {
|
||||
self.to_value()
|
||||
.ok()
|
||||
.and_then(|s| Some(is_number(s.strip_prefix('-')?)))
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Treat as a long-flag
|
||||
pub fn to_long(&self) -> Option<(Result<&'s str, &'s OsStr>, Option<&'s OsStr>)> {
|
||||
let raw = self.inner;
|
||||
let remainder = raw.strip_prefix("--")?;
|
||||
if remainder.is_empty() {
|
||||
debug_assert!(self.is_escape());
|
||||
return None;
|
||||
}
|
||||
|
||||
let (flag, value) = if let Some((p0, p1)) = remainder.split_once("=") {
|
||||
(p0, Some(p1))
|
||||
} else {
|
||||
(remainder, None)
|
||||
};
|
||||
let flag = flag.to_str().ok_or(flag);
|
||||
Some((flag, value))
|
||||
}
|
||||
|
||||
/// Can treat as a long-flag
|
||||
pub fn is_long(&self) -> bool {
|
||||
self.inner.starts_with("--") && !self.is_escape()
|
||||
}
|
||||
|
||||
/// Treat as a short-flag
|
||||
pub fn to_short(&self) -> Option<ShortFlags<'s>> {
|
||||
if let Some(remainder_os) = self.inner.strip_prefix("-") {
|
||||
if remainder_os.starts_with("-") {
|
||||
None
|
||||
} else if remainder_os.is_empty() {
|
||||
debug_assert!(self.is_stdio());
|
||||
None
|
||||
} else {
|
||||
Some(ShortFlags::new(remainder_os))
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Can treat as a short-flag
|
||||
pub fn is_short(&self) -> bool {
|
||||
self.inner.starts_with("-") && !self.is_stdio() && !self.inner.starts_with("--")
|
||||
}
|
||||
|
||||
/// Treat as a value
|
||||
///
|
||||
/// <div class="warning">
|
||||
///
|
||||
/// **NOTE:** May return a flag or an escape.
|
||||
///
|
||||
/// </div>
|
||||
pub fn to_value_os(&self) -> &'s OsStr {
|
||||
self.inner
|
||||
}
|
||||
|
||||
/// Treat as a value
|
||||
///
|
||||
/// <div class="warning">
|
||||
///
|
||||
/// **NOTE:** May return a flag or an escape.
|
||||
///
|
||||
/// </div>
|
||||
pub fn to_value(&self) -> Result<&'s str, &'s OsStr> {
|
||||
self.inner.to_str().ok_or(self.inner)
|
||||
}
|
||||
|
||||
/// Safely print an argument that may contain non-UTF8 content
|
||||
///
|
||||
/// This may perform lossy conversion, depending on the platform. If you would like an implementation which escapes the path please use Debug instead.
|
||||
pub fn display(&self) -> impl std::fmt::Display + 's {
|
||||
self.inner.to_string_lossy()
|
||||
}
|
||||
}
|
||||
|
||||
/// Walk through short flags within a [`ParsedArg`]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ShortFlags<'s> {
|
||||
inner: &'s OsStr,
|
||||
utf8_prefix: std::str::CharIndices<'s>,
|
||||
invalid_suffix: Option<&'s OsStr>,
|
||||
}
|
||||
|
||||
impl<'s> ShortFlags<'s> {
|
||||
fn new(inner: &'s OsStr) -> Self {
|
||||
let (utf8_prefix, invalid_suffix) = split_nonutf8_once(inner);
|
||||
let utf8_prefix = utf8_prefix.char_indices();
|
||||
Self {
|
||||
inner,
|
||||
utf8_prefix,
|
||||
invalid_suffix,
|
||||
}
|
||||
}
|
||||
|
||||
/// Move the iterator forward by `n` short flags
|
||||
pub fn advance_by(&mut self, n: usize) -> Result<(), usize> {
|
||||
for i in 0..n {
|
||||
self.next().ok_or(i)?.map_err(|_| i)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// No short flags left
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.invalid_suffix.is_none() && self.utf8_prefix.as_str().is_empty()
|
||||
}
|
||||
|
||||
/// Does the short flag look like a number
|
||||
///
|
||||
/// Ideally call this before doing any iterator
|
||||
pub fn is_negative_number(&self) -> bool {
|
||||
self.invalid_suffix.is_none() && is_number(self.utf8_prefix.as_str())
|
||||
}
|
||||
|
||||
/// Advance the iterator, returning the next short flag on success
|
||||
///
|
||||
/// On error, returns the invalid-UTF8 value
|
||||
pub fn next_flag(&mut self) -> Option<Result<char, &'s OsStr>> {
|
||||
if let Some((_, flag)) = self.utf8_prefix.next() {
|
||||
return Some(Ok(flag));
|
||||
}
|
||||
|
||||
if let Some(suffix) = self.invalid_suffix {
|
||||
self.invalid_suffix = None;
|
||||
return Some(Err(suffix));
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
/// Advance the iterator, returning everything left as a value
|
||||
pub fn next_value_os(&mut self) -> Option<&'s OsStr> {
|
||||
if let Some((index, _)) = self.utf8_prefix.next() {
|
||||
self.utf8_prefix = "".char_indices();
|
||||
self.invalid_suffix = None;
|
||||
// SAFETY: `char_indices` ensures `index` is at a valid UTF-8 boundary
|
||||
let remainder = unsafe { ext::split_at(self.inner, index).1 };
|
||||
return Some(remainder);
|
||||
}
|
||||
|
||||
if let Some(suffix) = self.invalid_suffix {
|
||||
self.invalid_suffix = None;
|
||||
return Some(suffix);
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s> Iterator for ShortFlags<'s> {
|
||||
type Item = Result<char, &'s OsStr>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.next_flag()
|
||||
}
|
||||
}
|
||||
|
||||
fn split_nonutf8_once(b: &OsStr) -> (&str, Option<&OsStr>) {
|
||||
match b.try_str() {
|
||||
Ok(s) => (s, None),
|
||||
Err(err) => {
|
||||
// SAFETY: `err.valid_up_to()`, which came from str::from_utf8(), is guaranteed
|
||||
// to be a valid UTF8 boundary
|
||||
let (valid, after_valid) = unsafe { ext::split_at(b, err.valid_up_to()) };
|
||||
let valid = valid.try_str().unwrap();
|
||||
(valid, Some(after_valid))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn is_number(arg: &str) -> bool {
|
||||
// Return true if this looks like an integer or a float where it's all
|
||||
// digits plus an optional single dot after some digits.
|
||||
//
|
||||
// For floats allow forms such as `1.`, `1.2`, `1.2e10`, etc.
|
||||
let mut seen_dot = false;
|
||||
let mut position_of_e = None;
|
||||
for (i, c) in arg.as_bytes().iter().enumerate() {
|
||||
match c {
|
||||
// Digits are always valid
|
||||
b'0'..=b'9' => {}
|
||||
|
||||
// Allow a `.`, but only one, only if it comes before an
|
||||
// optional exponent, and only if it's not the first character.
|
||||
b'.' if !seen_dot && position_of_e.is_none() && i > 0 => seen_dot = true,
|
||||
|
||||
// Allow an exponent `e`/`E` but only at most one after the first
|
||||
// character.
|
||||
b'e' | b'E' if position_of_e.is_none() && i > 0 => position_of_e = Some(i),
|
||||
|
||||
_ => return false,
|
||||
}
|
||||
}
|
||||
|
||||
// Disallow `-1e` which isn't a valid float since it doesn't actually have
|
||||
// an exponent.
|
||||
match position_of_e {
|
||||
Some(i) => i != arg.len() - 1,
|
||||
None => true,
|
||||
}
|
||||
}
|
||||
|
||||
#[doc = include_str!("../README.md")]
|
||||
#[cfg(doctest)]
|
||||
pub struct ReadmeDoctests;
|
||||
Reference in New Issue
Block a user