carapace_spec_clap-0.1.12/.github/dependabot.yml 0000644 0000000 0000000 00000000155 10461020230 0017646 0 ustar 0000000 0000000 version: 2
updates:
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "weekly"
carapace_spec_clap-0.1.12/.github/workflows/rust.yml 0000644 0000000 0000000 00000001714 10461020230 0020575 0 ustar 0000000 0000000 name: Rust
on:
pull_request:
push:
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: shallow clone
uses: actions/checkout@v3
- name: deep clone
uses: actions/checkout@v3
if: startsWith(github.ref, 'refs/tags/v')
with:
fetch-depth: 0
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
if: startsWith(github.ref, 'refs/tags/v')
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish crate
if: startsWith(github.ref, 'refs/tags/v')
run: sed -i "s_0.1.0-PLACEHOLDER_${GITHUB_REF/refs\/tags\/v/}_" Cargo.toml && cargo publish --token ${CRATES_TOKEN} --allow-dirty
env:
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }} carapace_spec_clap-0.1.12/.gitignore 0000644 0000000 0000000 00000000010 10461020230 0015434 0 ustar 0000000 0000000 /target
carapace_spec_clap-0.1.12/.goreleaser.yml 0000644 0000000 0000000 00000000027 10461020230 0016405 0 ustar 0000000 0000000 builds:
- skip: true
carapace_spec_clap-0.1.12/Cargo.lock 0000644 00000033537 00000000001 0012653 0 ustar # This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "anstream"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e579a7752471abc2a8268df8b20005e3eadd975f585398f17efcfd8d4927371"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is-terminal",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d"
[[package]]
name = "anstyle-parse"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "anstyle-wincon"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bcd8291a340dd8ac70e18878bc4501dd7b4ff970cfa21c207d36ece51ea88fd"
dependencies = [
"anstyle",
"windows-sys 0.48.0",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "carapace_spec_clap"
version = "0.1.12"
dependencies = [
"clap",
"clap_complete",
"indexmap",
"serde",
"serde_yaml",
"snapbox",
]
[[package]]
name = "cc"
version = "1.0.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4"
[[package]]
name = "clap"
version = "4.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eab9e8ceb9afdade1ab3f0fd8dbce5b1b2f468ad653baf10e771781b2b67b73"
dependencies = [
"clap_builder",
]
[[package]]
name = "clap_builder"
version = "4.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f2763db829349bf00cfc06251268865ed4363b93a943174f638daf3ecdba2cd"
dependencies = [
"anstyle",
"clap_lex",
]
[[package]]
name = "clap_complete"
version = "4.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fc443334c81a804575546c5a8a79b4913b50e28d69232903604cada1de817ce"
dependencies = [
"clap",
]
[[package]]
name = "clap_lex"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "equivalent"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1"
[[package]]
name = "errno"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
dependencies = [
"errno-dragonfly",
"libc",
"winapi",
]
[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "hashbrown"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
[[package]]
name = "hermit-abi"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
[[package]]
name = "indexmap"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
dependencies = [
"equivalent",
"hashbrown",
"serde",
]
[[package]]
name = "io-lifetimes"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e394faa0efb47f9f227f1cd89978f854542b318a6f64fa695489c9c993056656"
dependencies = [
"libc",
"windows-sys 0.42.0",
]
[[package]]
name = "is-terminal"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8687c819457e979cc940d09cb16e42a1bf70aa6b60a549de6d3a62a0ee90c69e"
dependencies = [
"hermit-abi",
"io-lifetimes",
"rustix",
"windows-sys 0.45.0",
]
[[package]]
name = "itoa"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
[[package]]
name = "libc"
version = "0.2.136"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55edcf6c0bb319052dea84732cf99db461780fd5e8d3eb46ab6ff312ab31f197"
[[package]]
name = "linux-raw-sys"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f"
[[package]]
name = "normalize-line-endings"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be"
[[package]]
name = "proc-macro2"
version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78803b62cbf1f46fde80d7c0e803111524b9877184cfe7c3033659490ac7a7da"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rustix"
version = "0.36.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fe885c3a125aa45213b68cc1472a49880cb5923dc23f522ad2791b882228778"
dependencies = [
"bitflags",
"errno",
"io-lifetimes",
"libc",
"linux-raw-sys",
"windows-sys 0.45.0",
]
[[package]]
name = "ryu"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
[[package]]
name = "serde"
version = "1.0.171"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.171"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_yaml"
version = "0.9.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da6075b41c7e3b079e5f246eb6094a44850d3a4c25a67c581c80796c80134012"
dependencies = [
"indexmap",
"itoa",
"ryu",
"serde",
"unsafe-libyaml",
]
[[package]]
name = "similar"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62ac7f900db32bf3fd12e0117dd3dc4da74bc52ebaac97f39668446d89694803"
[[package]]
name = "snapbox"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6bccd62078347f89a914e3004d94582e13824d4e3d8a816317862884c423835"
dependencies = [
"anstream",
"anstyle",
"normalize-line-endings",
"similar",
"snapbox-macros",
]
[[package]]
name = "snapbox-macros"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eaaf09df9f0eeae82be96290918520214530e738a7fe5a351b0f24cf77c0ca31"
dependencies = [
"anstream",
]
[[package]]
name = "syn"
version = "2.0.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15e3fc8c0c74267e2df136e5e5fb656a464158aa57624053375eb9c8c6e25ae2"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
[[package]]
name = "unsafe-libyaml"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad2024452afd3874bf539695e04af6732ba06517424dbf958fdb16a01f3bef6c"
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
dependencies = [
"windows_aarch64_gnullvm 0.42.2",
"windows_aarch64_msvc 0.42.2",
"windows_i686_gnu 0.42.2",
"windows_i686_msvc 0.42.2",
"windows_x86_64_gnu 0.42.2",
"windows_x86_64_gnullvm 0.42.2",
"windows_x86_64_msvc 0.42.2",
]
[[package]]
name = "windows-sys"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
"windows-targets 0.42.2",
]
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets 0.48.0",
]
[[package]]
name = "windows-targets"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
dependencies = [
"windows_aarch64_gnullvm 0.42.2",
"windows_aarch64_msvc 0.42.2",
"windows_i686_gnu 0.42.2",
"windows_i686_msvc 0.42.2",
"windows_x86_64_gnu 0.42.2",
"windows_x86_64_gnullvm 0.42.2",
"windows_x86_64_msvc 0.42.2",
]
[[package]]
name = "windows-targets"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
dependencies = [
"windows_aarch64_gnullvm 0.48.0",
"windows_aarch64_msvc 0.48.0",
"windows_i686_gnu 0.48.0",
"windows_i686_msvc 0.48.0",
"windows_x86_64_gnu 0.48.0",
"windows_x86_64_gnullvm 0.48.0",
"windows_x86_64_msvc 0.48.0",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
[[package]]
name = "windows_i686_gnu"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
[[package]]
name = "windows_i686_gnu"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
[[package]]
name = "windows_i686_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
[[package]]
name = "windows_i686_msvc"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
carapace_spec_clap-0.1.12/Cargo.toml 0000644 00000002222 00000000001 0012661 0 ustar # 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 = "2021"
name = "carapace_spec_clap"
version = "0.1.12"
description = "spec generation for clap-rs/clap"
readme = "README.md"
keywords = [
"cli",
"completion",
"clap",
"carapace",
]
categories = ["command-line-interface"]
license = "MIT"
repository = "https://github.com/rsteube/carapace-spec-clap"
[lib]
[dependencies.clap]
version = "4.3.12"
features = ["std"]
default-features = false
[dependencies.clap_complete]
version = "4.3.2"
[dependencies.indexmap]
version = "2.0.0"
features = ["serde"]
[dependencies.serde]
version = "1.0"
features = ["derive"]
[dependencies.serde_yaml]
version = "0.9"
[dev-dependencies.snapbox]
version = "0.4"
features = ["diff"]
carapace_spec_clap-0.1.12/Cargo.toml.orig 0000644 0000000 0000000 00000001161 10461020230 0016343 0 ustar 0000000 0000000 [package]
name = "carapace_spec_clap"
description = "spec generation for clap-rs/clap"
version = "0.1.12"
edition = "2021"
repository = "https://github.com/rsteube/carapace-spec-clap"
license = "MIT"
categories = ["command-line-interface"]
keywords = ["cli", "completion", "clap", "carapace"]
[lib]
[dependencies]
clap = { version = "4.3.12", default-features = false, features = ["std"] }
clap_complete = { version = "4.3.2" }
indexmap = {version = "2.0.0", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9"
[dev-dependencies]
snapbox = { version = "0.4", features = ["diff"] }
carapace_spec_clap-0.1.12/LICENSE 0000644 0000000 0000000 00000002050 10461020230 0014457 0 ustar 0000000 0000000 MIT License
Copyright (c) 2022 rsteube
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.
carapace_spec_clap-0.1.12/README.md 0000644 0000000 0000000 00000005011 10461020230 0014731 0 ustar 0000000 0000000 # carapace-spec-clap
[](https://crates.io/crates/carapace_spec_clap)
[Spec](https://github.com/rsteube/carapace-spec) generation for [clap-rs/clap](https://github.com/clap-rs/clap)
[](https://asciinema.org/a/548145)
```rust
use carapace_spec_clap::Spec;
use clap::{Arg, ArgAction, Command, ValueHint};
use clap_complete::generate;
use std::io;
fn main() {
let mut cmd = Command::new("example")
.aliases(["alias1", "alias2"])
.about("example command")
.arg(
Arg::new("help")
.long("help")
.short('h')
.help("show help")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("optional")
.long("optional")
.help("optional argument")
.require_equals(true)
.value_hint(ValueHint::Username),
)
.arg(
Arg::new("value")
.short('v')
.help("takes argument")
.value_parser(["one", "two", "three"]),
)
.subcommand(
Command::new("subcommand")
.about("example subcommand")
.arg(
Arg::new("command")
.long("command")
.short('c')
.help("execute command")
.value_hint(ValueHint::CommandName),
)
.arg(
Arg::new("pos1")
.value_parser(["four", "five", "six"])
.value_hint(ValueHint::DirPath),
)
.arg(
Arg::new("posAny")
.num_args(1..)
.value_hint(ValueHint::Hostname),
),
);
generate(Spec, &mut cmd, "example", &mut io::stdout());
}
```
```yaml
name: example
aliases:
- alias1
- alias2
description: example command
flags:
-h, --help: show help
--optional?: optional argument
-v=: takes argument
completion:
flag:
optional:
- $_os.Users
v:
- one
- two
- three
commands:
- name: subcommand
description: example subcommand
flags:
-c, --command=: execute command
completion:
flag:
command:
- $_os.PathExecutables
- $files
positional:
- - $directories
- four
- five
- six
positionalany:
- $_net.Hosts
```
carapace_spec_clap-0.1.12/dist/CHANGELOG.md 0000644 0000000 0000000 00000007244 10461020230 0016240 0 ustar 0000000 0000000 ## Changelog
* 7a72bd8 Merge pull request #100 from rsteube/support-hidden
* d903df3 Merge pull request #98 from rsteube/dependabot/cargo/clap-4.3.12
* 7446092 support hidden
* af67c5c Merge pull request #99 from rsteube/dependabot/cargo/serde_yaml-0.9.23
* 9b62673 Bump serde_yaml from 0.9.22 to 0.9.23
* 9d44b07 Bump clap from 4.3.11 to 4.3.12
* e34e23a Merge pull request #95 from rsteube/dependabot/cargo/clap_complete-4.3.2
* 4b0fc5f Bump clap_complete from 4.3.1 to 4.3.2
* 48eeb1a Merge pull request #96 from rsteube/dependabot/cargo/serde-1.0.171
* 2fb2aaa Merge pull request #97 from rsteube/dependabot/cargo/clap-4.3.11
* d706f47 Bump clap from 4.3.10 to 4.3.11
* 695e30d Bump serde from 1.0.164 to 1.0.171
* 01b7268 Merge pull request #93 from rsteube/dependabot/cargo/indexmap-2.0.0
* 68b81a4 Bump indexmap from 1.9.3 to 2.0.0
* 338a8a5 Merge pull request #94 from rsteube/dependabot/cargo/clap-4.3.10
* 8cd4f73 Bump clap from 4.3.8 to 4.3.10
* 3bd208c Merge pull request #92 from rsteube/dependabot/cargo/serde_yaml-0.9.22
* 698670b Merge pull request #91 from rsteube/dependabot/cargo/clap-4.3.8
* ea9ac42 Bump serde_yaml from 0.9.21 to 0.9.22
* 2ea24fd Bump clap from 4.3.4 to 4.3.8
* dc59ac7 Merge pull request #90 from rsteube/dependabot/cargo/clap-4.3.4
* 8a2a4ee Bump clap from 4.3.3 to 4.3.4
* da9095e Merge pull request #88 from rsteube/dependabot/cargo/serde-1.0.164
* 13191c9 Bump serde from 1.0.163 to 1.0.164
* bac0bba Merge pull request #87 from rsteube/dependabot/cargo/clap_complete-4.3.1
* ca5c604 Bump clap_complete from 4.2.3 to 4.3.1
* 0a5cd2a Merge pull request #89 from rsteube/dependabot/cargo/clap-4.3.3
* e81c992 Bump clap from 4.2.7 to 4.3.3
* 68ea598 Merge pull request #82 from rsteube/dependabot/cargo/clap_complete-4.2.3
* b9a36f6 Merge pull request #83 from rsteube/dependabot/cargo/serde-1.0.163
* 608055c Bump serde from 1.0.162 to 1.0.163
* 4a6d79a Bump clap_complete from 4.2.1 to 4.2.3
* 241e46e Merge pull request #80 from rsteube/dependabot/cargo/clap-4.2.7
* 86f9727 Merge pull request #81 from rsteube/dependabot/cargo/serde-1.0.162
* b5cea5e Bump serde from 1.0.160 to 1.0.162
* 9a01459 Bump clap from 4.2.5 to 4.2.7
* 21aaa5a Merge pull request #79 from rsteube/dependabot/cargo/clap-4.2.5
* 3e1c487 Bump clap from 4.2.4 to 4.2.5
* a65036f Merge pull request #77 from rsteube/dependabot/cargo/clap-4.2.4
* 1e4153e Bump clap from 4.2.2 to 4.2.4
* 87f5474 Merge pull request #78 from rsteube/dependabot/cargo/clap_complete-4.2.1
* 07f87ef Bump clap_complete from 4.2.0 to 4.2.1
* 35d5606 Merge pull request #75 from rsteube/dependabot/cargo/snapbox-0.4.11
* 83989af Merge pull request #74 from rsteube/dependabot/cargo/serde-1.0.160
* 3fef50c Merge pull request #76 from rsteube/dependabot/cargo/clap-4.2.2
* 50b6a32 Bump clap from 4.2.1 to 4.2.2
* 4be6bf6 Bump snapbox from 0.4.10 to 0.4.11
* 9c47542 Bump serde from 1.0.159 to 1.0.160
* bef3482 Merge pull request #73 from rsteube/dependabot/cargo/serde_yaml-0.9.21
* 2c07eb6 Bump serde_yaml from 0.9.19 to 0.9.21
* fb2e5bf Merge pull request #71 from rsteube/dependabot/cargo/clap_complete-4.2.0
* 9e5c58c Bump clap_complete from 4.1.5 to 4.2.0
* 90a60fc Merge pull request #72 from rsteube/dependabot/cargo/serde-1.0.159
* f31e69d Merge pull request #70 from rsteube/dependabot/cargo/clap-4.2.1
* 1f93087 Bump serde from 1.0.158 to 1.0.159
* 9e5c5c8 Bump clap from 4.1.13 to 4.2.1
* 1d5cb1c Merge pull request #67 from rsteube/dependabot/cargo/clap-4.1.13
* 800ba5a Bump clap from 4.1.11 to 4.1.13
* 5431ca8 Merge pull request #69 from rsteube/dependabot/cargo/indexmap-1.9.3
* ec1d086 Merge pull request #68 from rsteube/dependabot/cargo/serde-1.0.158
* 6c9b430 Bump indexmap from 1.9.2 to 1.9.3
* 0024492 Bump serde from 1.0.157 to 1.0.158
carapace_spec_clap-0.1.12/dist/artifacts.json 0000644 0000000 0000000 00000000002 10461020230 0017263 0 ustar 0000000 0000000 [] carapace_spec_clap-0.1.12/dist/config.yaml 0000644 0000000 0000000 00000007031 10461020230 0016552 0 ustar 0000000 0000000 project_name: carapace-spec-clap
release:
github:
owner: rsteube
name: carapace-spec-clap
name_template: '{{.Tag}}'
builds:
- id: carapace-spec-clap
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
- "386"
goarm:
- "6"
gomips:
- hardfloat
goamd64:
- v1
targets:
- linux_amd64_v1
- linux_arm64
- linux_386
- darwin_amd64_v1
- darwin_arm64
- windows_amd64_v1
- windows_arm64
- windows_386
dir: .
main: .
binary: carapace-spec-clap
builder: go
skip: true
gobinary: go
command: build
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser
archives:
- id: default
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}'
format: tar.gz
files:
- src: license*
- src: LICENSE*
- src: readme*
- src: README*
- src: changelog*
- src: CHANGELOG*
snapshot:
name_template: '{{ .Version }}-SNAPSHOT-{{ .ShortCommit }}'
checksum:
name_template: '{{ .ProjectName }}_{{ .Version }}_checksums.txt'
algorithm: sha256
dist: dist
env_files:
github_token: ~/.config/goreleaser/github_token
gitlab_token: ~/.config/goreleaser/gitlab_token
gitea_token: ~/.config/goreleaser/gitea_token
source:
name_template: '{{ .ProjectName }}-{{ .Version }}'
format: tar.gz
gomod:
gobinary: go
announce:
twitter:
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
mastodon:
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
server: ""
reddit:
title_template: '{{ .ProjectName }} {{ .Tag }} is out!'
url_template: '{{ .ReleaseURL }}'
slack:
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
username: GoReleaser
discord:
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
author: GoReleaser
color: "3888754"
icon_url: https://goreleaser.com/static/avatar.png
teams:
title_template: '{{ .ProjectName }} {{ .Tag }} is out!'
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
color: '#2D313E'
icon_url: https://goreleaser.com/static/avatar.png
smtp:
subject_template: '{{ .ProjectName }} {{ .Tag }} is out!'
body_template: 'You can view details from: {{ .ReleaseURL }}'
mattermost:
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
title_template: '{{ .ProjectName }} {{ .Tag }} is out!'
username: GoReleaser
linkedin:
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
telegram:
message_template: '{{ .ProjectName }} {{ mdv2escape .Tag }} is out! Check it out at {{ mdv2escape .ReleaseURL }}'
parse_mode: MarkdownV2
webhook:
message_template: '{ "message": "{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}"}'
content_type: application/json; charset=utf-8
opencollective:
title_template: '{{ .Tag }}'
message_template: '{{ .ProjectName }} {{ .Tag }} is out!
Check it out at {{ .ReleaseURL }}'
git:
tag_sort: -version:refname
github_urls:
download: https://github.com
gitlab_urls:
download: https://gitlab.com
carapace_spec_clap-0.1.12/dist/metadata.json 0000644 0000000 0000000 00000000351 10461020230 0017072 0 ustar 0000000 0000000 {"project_name":"carapace-spec-clap","tag":"v0.1.12","previous_tag":"v0.1.11","version":"0.1.12","commit":"7a72bd87ee33307942c2aafdc2a214bb0265a2f5","date":"2023-07-17T15:19:56.700292513Z","runtime":{"goos":"linux","goarch":"amd64"}} carapace_spec_clap-0.1.12/examples/carapace_spec.rs 0000644 0000000 0000000 00000003173 10461020230 0020416 0 ustar 0000000 0000000 use carapace_spec_clap::Spec;
use clap::{Arg, ArgAction, Command, ValueHint};
use clap_complete::generate;
use std::io;
fn main() {
let mut cmd = Command::new("example")
.aliases(["alias1", "alias2"])
.about("example command")
.arg(
Arg::new("help")
.long("help")
.short('h')
.help("show help")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("optional")
.long("optional")
.help("optional argument")
.require_equals(true)
.value_hint(ValueHint::Username),
)
.arg(
Arg::new("value")
.short('v')
.help("takes argument")
.value_parser(["one", "two", "three"]),
)
.subcommand(
Command::new("subcommand")
.about("example subcommand")
.arg(
Arg::new("command")
.long("command")
.short('c')
.help("execute command")
.value_hint(ValueHint::CommandName),
)
.arg(
Arg::new("pos1")
.value_parser(["four", "five", "six"])
.value_hint(ValueHint::DirPath),
)
.arg(
Arg::new("posAny")
.num_args(1..)
.value_hint(ValueHint::Hostname),
),
);
generate(Spec, &mut cmd, "example", &mut io::stdout());
}
carapace_spec_clap-0.1.12/examples/git.rs 0000644 0000000 0000000 00000004123 10461020230 0016424 0 ustar 0000000 0000000 use carapace_spec_clap::Spec;
use clap::{arg, Command};
use clap_complete::generate;
use std::io;
use std::path::PathBuf;
fn git_cmd() -> Command {
Command::new("git")
.about("A fictional versioning CLI")
.subcommand_required(true)
.arg_required_else_help(true)
.allow_external_subcommands(true)
.subcommand(
Command::new("clone")
.about("Clones repos")
.arg(arg!( "The remote to clone"))
.arg_required_else_help(true),
)
.subcommand(
Command::new("diff")
.about("Compare two commits")
.arg(arg!(base: [COMMIT]))
.arg(arg!(head: [COMMIT]))
.arg(arg!(path: [PATH]).last(true))
.arg(
arg!(--color )
.value_parser(["always", "auto", "never"])
.num_args(0..=1)
.require_equals(true)
.default_value("auto")
.default_missing_value("always"),
),
)
.subcommand(
Command::new("push")
.about("pushes things")
.arg(arg!( "The remote to target"))
.arg_required_else_help(true),
)
.subcommand(
Command::new("add")
.about("adds things")
.arg_required_else_help(true)
.arg(arg!( ... "Stuff to add").value_parser(clap::value_parser!(PathBuf))),
)
.subcommand(
Command::new("stash")
.args_conflicts_with_subcommands(true)
.args(push_args())
.subcommand(Command::new("push").args(push_args()))
.subcommand(Command::new("pop").arg(arg!([STASH])))
.subcommand(Command::new("apply").arg(arg!([STASH]))),
)
}
fn push_args() -> Vec {
vec![arg!(-m --message )]
}
fn main() {
let mut cmd = git_cmd();
generate(Spec, &mut cmd, "myapp", &mut io::stdout());
}
carapace_spec_clap-0.1.12/src/carapace_spec.rs 0000644 0000000 0000000 00000016740 10461020230 0017373 0 ustar 0000000 0000000 use clap::{
Arg, ArgAction,
ValueHint::{self, *},
};
use clap_complete::*;
use indexmap::IndexMap as Map;
use serde::Serialize;
fn default(t: &T) -> bool {
*t == Default::default()
}
#[derive(Default, Serialize)]
pub struct Command {
pub name: String,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub aliases: Vec,
pub description: String,
#[serde(skip_serializing_if = "default")]
pub hidden: bool,
#[serde(skip_serializing_if = "Map::is_empty")]
pub flags: Map,
#[serde(skip_serializing_if = "Map::is_empty")]
pub persistentflags: Map,
#[serde(skip_serializing_if = "Completion::is_empty")]
pub completion: Completion,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub commands: Vec,
}
#[derive(Default, Serialize)]
pub struct Completion {
#[serde(skip_serializing_if = "Map::is_empty")]
pub flag: Map>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub positional: Vec>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub positionalany: Vec,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub dash: Vec>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub dashany: Vec,
}
impl Completion {
pub fn is_empty(&self) -> bool {
self.flag.is_empty()
&& self.positionalany.is_empty()
&& self.positionalany.is_empty()
&& self.dash.is_empty()
&& self.dashany.is_empty()
}
}
pub struct Spec;
impl Generator for Spec {
fn file_name(&self, name: &str) -> String {
format!("{}.yaml", name)
}
fn generate(&self, cmd: &clap::Command, buf: &mut dyn std::io::Write) {
let command = command_for(cmd, true);
let serialized = serde_yaml::to_string(&command).unwrap();
buf.write_all(serialized.as_bytes())
.expect("Failed to write to generated file");
}
}
fn command_for(cmd: &clap::Command, root: bool) -> Command {
Command {
name: cmd.get_name().to_owned(),
aliases: cmd.get_all_aliases().map(String::from).collect(),
description: cmd.get_about().unwrap_or_default().to_string(),
hidden: cmd.is_hide_set(),
flags: flags_for(cmd, false),
persistentflags: if let true = root {
flags_for(cmd, true)
} else {
Default::default()
},
completion: Completion {
flag: flag_completions_for(cmd),
positional: positional_completion_for(cmd),
positionalany: positionalany_completion_for(cmd),
..Default::default()
},
commands: cmd
.get_subcommands()
.filter(|c| !c.is_hide_set())
.map(|c| command_for(c, false))
.collect(),
..Default::default()
}
}
fn flags_for(cmd: &clap::Command, persistent: bool) -> Map {
let mut m = Map::new();
let mut arguments = cmd
.get_arguments()
.filter(|o| !o.is_positional())
.filter(|o| !o.is_hide_set())
.filter(|o| o.is_global_set() == persistent)
.map(|x| x.to_owned())
.collect::>();
arguments.sort_by_key(|o| {
o.get_long()
.unwrap_or(&o.get_short().unwrap_or_default().to_string())
.to_owned()
});
for arg in arguments {
let signature = if let Some(long) = arg.get_long() {
if let Some(short) = arg.get_short() {
format!("-{}, --{}", short, long)
} else {
format!("--{}", long)
}
} else {
format!("-{}", arg.get_short().unwrap())
};
m.insert(
format!("{}{}", signature, modifier_for(&arg)),
arg.get_help().unwrap_or_default().to_string(),
);
}
m
}
fn positionalany_completion_for(cmd: &clap::Command) -> Vec {
let mut positionals = cmd.get_positionals().collect::>();
positionals.sort_by_key(|a| a.get_index());
if let Some(last) = positionals.last() {
if last.get_num_args().unwrap_or_default().max_values() == usize::MAX {
// TODO different way to detect unboundend?
return action_for(last.get_value_hint())
.into_iter()
.chain(values_for(last))
.collect::>();
}
}
vec![]
}
fn positional_completion_for(cmd: &clap::Command) -> Vec> {
let mut positionals = cmd.get_positionals().collect::>();
positionals.sort_by_key(|a| a.get_index());
positionals
.into_iter()
.filter(|p| p.get_num_args().unwrap_or_default().max_values() != usize::MAX) // filter last vararg pos (added to positionalany)
.map(|p| {
action_for(p.get_value_hint())
.into_iter()
.chain(values_for(p))
.collect::>()
})
.collect()
}
fn flag_completions_for(cmd: &clap::Command) -> Map> {
let mut m = Map::new();
let mut options = cmd
.get_opts()
.filter(|o| !o.is_positional())
.filter(|o| !o.is_hide_set())
.map(|x| x.to_owned())
.collect::>();
options.sort_by_key(|o| {
o.get_long()
.unwrap_or(&o.get_short().unwrap_or_default().to_string())
.to_owned()
});
for option in options {
let name = option
.get_long()
.unwrap_or(&option.get_short().unwrap_or_default().to_string())
.to_owned();
let action = action_for(option.get_value_hint())
.into_iter()
.chain(values_for(&option))
.collect::>();
if !action.is_empty() {
m.insert(name, action);
}
}
m
}
fn values_for(option: &Arg) -> Vec {
let mut v = Vec::new();
if let Some(values) = generator::utils::possible_values(option) {
for value in values {
if let Some(description) = value.get_help() {
v.push(format!("{}\t{}", value.get_name(), description));
} else {
v.push(value.get_name().to_owned());
}
}
}
v
}
fn modifier_for(option: &Arg) -> String {
let mut modifier = vec![];
if option.get_action().takes_values() {
if option.is_hide_set() {
modifier.push("&")
}
if option.is_required_set() {
modifier.push("!")
}
if option.is_require_equals_set() {
modifier.push("?");
} else {
modifier.push("=");
}
}
if let ArgAction::Append | ArgAction::Count = option.get_action() {
modifier.push("*");
}
modifier.join("")
}
fn action_for<'a>(hint: ValueHint) -> Vec {
match hint {
// TODO actions for command are wrong
Unknown => vec![],
Other => vec![],
AnyPath => vec!["$files"],
FilePath => vec!["$files"],
DirPath => vec!["$directories"],
ExecutablePath => vec!["$files"],
CommandName => vec!["$_os.PathExecutables", "$files"],
CommandString => vec!["$_os.PathExecutables", "$files"],
CommandWithArguments => vec!["TODO"], // TODO
Username => vec!["$_os.Users"],
Hostname => vec!["$_net.Hosts"],
Url => vec![],
EmailAddress => vec![],
_ => vec![],
}
.into_iter()
.map(String::from)
.collect()
}
carapace_spec_clap-0.1.12/src/lib.rs 0000644 0000000 0000000 00000000060 10461020230 0015354 0 ustar 0000000 0000000 mod carapace_spec;
pub use carapace_spec::Spec;
carapace_spec_clap-0.1.12/tests/carapace_spec.rs 0000644 0000000 0000000 00000003362 10461020230 0017742 0 ustar 0000000 0000000 mod common;
#[test]
fn basic() {
let name = "basic";
let cmd = common::basic_command(name);
common::assert_matches_path(
"tests/snapshots/basic.yaml",
carapace_spec_clap::Spec,
cmd,
name,
);
}
#[test]
fn feature_sample() {
let name = "feature_sample";
let cmd = common::feature_sample_command(name);
common::assert_matches_path(
"tests/snapshots/feature_sample.yaml",
carapace_spec_clap::Spec,
cmd,
name,
);
}
#[test]
fn special_commands() {
let name = "special_commands";
let cmd = common::special_commands_command(name);
common::assert_matches_path(
"tests/snapshots/special_commands.yaml",
carapace_spec_clap::Spec,
cmd,
name,
);
}
#[test]
fn quoting() {
let name = "quoting";
let cmd = common::quoting_command(name);
common::assert_matches_path(
"tests/snapshots/quoting.yaml",
carapace_spec_clap::Spec,
cmd,
name,
);
}
#[test]
fn aliases() {
let name = "aliases";
let cmd = common::aliases_command(name);
common::assert_matches_path(
"tests/snapshots/aliases.yaml",
carapace_spec_clap::Spec,
cmd,
name,
);
}
#[test]
fn sub_subcommands() {
let name = "sub_subcommands";
let cmd = common::sub_subcommands_command(name);
common::assert_matches_path(
"tests/snapshots/sub_subcommands.yaml",
carapace_spec_clap::Spec,
cmd,
name,
);
}
#[test]
fn value_hint() {
let name = "value_hint";
let cmd = common::value_hint_command(name);
common::assert_matches_path(
"tests/snapshots/value_hint.yaml",
carapace_spec_clap::Spec,
cmd,
name,
);
}
carapace_spec_clap-0.1.12/tests/common.rs 0000644 0000000 0000000 00000021027 10461020230 0016457 0 ustar 0000000 0000000 pub fn basic_command(name: &'static str) -> clap::Command {
clap::Command::new(name)
.arg(
clap::Arg::new("config")
.short('c')
.global(true)
.action(clap::ArgAction::SetTrue),
)
.arg(
clap::Arg::new("v")
.short('v')
.conflicts_with("config")
.action(clap::ArgAction::SetTrue),
)
.subcommand(
clap::Command::new("test").about("Subcommand").arg(
clap::Arg::new("debug")
.short('d')
.action(clap::ArgAction::Count),
),
)
}
pub fn feature_sample_command(name: &'static str) -> clap::Command {
clap::Command::new(name)
.version("3.0")
.propagate_version(true)
.about("Tests completions")
.arg(
clap::Arg::new("file")
.value_hint(clap::ValueHint::FilePath)
.help("some input file"),
)
.arg(
clap::Arg::new("config")
.action(clap::ArgAction::Count)
.help("some config file")
.short('c')
.visible_short_alias('C')
.long("config")
.visible_alias("conf"),
)
.arg(clap::Arg::new("choice").value_parser(["first", "second"]))
.subcommand(
clap::Command::new("test").about("tests things").arg(
clap::Arg::new("case")
.long("case")
.action(clap::ArgAction::Set)
.help("the case to test"),
),
)
}
pub fn special_commands_command(name: &'static str) -> clap::Command {
feature_sample_command(name)
.subcommand(
clap::Command::new("some_cmd")
.about("tests other things")
.arg(
clap::Arg::new("config")
.long("config")
.hide(true)
.action(clap::ArgAction::Set)
.require_equals(true)
.help("the other case to test"),
)
.arg(clap::Arg::new("path").num_args(1..)),
)
.subcommand(clap::Command::new("some-cmd-with-hyphens").alias("hyphen"))
.subcommand(clap::Command::new("some-hidden-cmd").hide(true))
}
pub fn quoting_command(name: &'static str) -> clap::Command {
clap::Command::new(name)
.version("3.0")
.arg(
clap::Arg::new("single-quotes")
.long("single-quotes")
.action(clap::ArgAction::SetTrue)
.help("Can be 'always', 'auto', or 'never'"),
)
.arg(
clap::Arg::new("double-quotes")
.long("double-quotes")
.action(clap::ArgAction::SetTrue)
.help("Can be \"always\", \"auto\", or \"never\""),
)
.arg(
clap::Arg::new("backticks")
.long("backticks")
.action(clap::ArgAction::SetTrue)
.help("For more information see `echo test`"),
)
.arg(
clap::Arg::new("backslash")
.long("backslash")
.action(clap::ArgAction::SetTrue)
.help("Avoid '\\n'"),
)
.arg(
clap::Arg::new("brackets")
.long("brackets")
.action(clap::ArgAction::SetTrue)
.help("List packages [filter]"),
)
.arg(
clap::Arg::new("expansions")
.long("expansions")
.action(clap::ArgAction::SetTrue)
.help("Execute the shell command with $SHELL"),
)
.subcommands([
clap::Command::new("cmd-single-quotes").about("Can be 'always', 'auto', or 'never'"),
clap::Command::new("cmd-double-quotes")
.about("Can be \"always\", \"auto\", or \"never\""),
clap::Command::new("cmd-backticks").about("For more information see `echo test`"),
clap::Command::new("cmd-backslash").about("Avoid '\\n'"),
clap::Command::new("cmd-brackets").about("List packages [filter]"),
clap::Command::new("cmd-expansions").about("Execute the shell command with $SHELL"),
])
}
pub fn aliases_command(name: &'static str) -> clap::Command {
clap::Command::new(name)
.version("3.0")
.about("testing bash completions")
.arg(
clap::Arg::new("flag")
.short('f')
.visible_short_alias('F')
.long("flag")
.action(clap::ArgAction::SetTrue)
.visible_alias("flg")
.help("cmd flag"),
)
.arg(
clap::Arg::new("option")
.short('o')
.visible_short_alias('O')
.long("option")
.visible_alias("opt")
.help("cmd option")
.action(clap::ArgAction::Set),
)
.arg(clap::Arg::new("positional"))
}
pub fn sub_subcommands_command(name: &'static str) -> clap::Command {
feature_sample_command(name).subcommand(
clap::Command::new("some_cmd")
.about("top level subcommand")
.subcommand(
clap::Command::new("sub_cmd").about("sub-subcommand").arg(
clap::Arg::new("config")
.long("config")
.action(clap::ArgAction::Set)
.value_parser([clap::builder::PossibleValue::new(
"Lest quotes aren't escaped.",
)])
.help("the other case to test"),
),
),
)
}
pub fn value_hint_command(name: &'static str) -> clap::Command {
clap::Command::new(name)
.arg(
clap::Arg::new("choice")
.long("choice")
.action(clap::ArgAction::Set)
.value_parser(["bash", "fish", "zsh"]),
)
.arg(
clap::Arg::new("unknown")
.long("unknown")
.value_hint(clap::ValueHint::Unknown),
)
.arg(
clap::Arg::new("other")
.long("other")
.value_hint(clap::ValueHint::Other),
)
.arg(
clap::Arg::new("path")
.long("path")
.short('p')
.value_hint(clap::ValueHint::AnyPath),
)
.arg(
clap::Arg::new("file")
.long("file")
.short('f')
.value_hint(clap::ValueHint::FilePath),
)
.arg(
clap::Arg::new("dir")
.long("dir")
.short('d')
.value_hint(clap::ValueHint::DirPath),
)
.arg(
clap::Arg::new("exe")
.long("exe")
.short('e')
.value_hint(clap::ValueHint::ExecutablePath),
)
.arg(
clap::Arg::new("cmd_name")
.long("cmd-name")
.value_hint(clap::ValueHint::CommandName),
)
.arg(
clap::Arg::new("cmd")
.long("cmd")
.short('c')
.value_hint(clap::ValueHint::CommandString),
)
.arg(
clap::Arg::new("command_with_args")
.action(clap::ArgAction::Set)
.num_args(1..)
.trailing_var_arg(true)
.value_hint(clap::ValueHint::CommandWithArguments),
)
.arg(
clap::Arg::new("user")
.short('u')
.long("user")
.value_hint(clap::ValueHint::Username),
)
.arg(
clap::Arg::new("host")
.short('H')
.long("host")
.value_hint(clap::ValueHint::Hostname),
)
.arg(
clap::Arg::new("url")
.long("url")
.value_hint(clap::ValueHint::Url),
)
.arg(
clap::Arg::new("email")
.long("email")
.value_hint(clap::ValueHint::EmailAddress),
)
}
pub fn assert_matches_path(
expected_path: impl AsRef,
gen: impl clap_complete::Generator,
mut cmd: clap::Command,
name: &'static str,
) {
let mut buf = vec![];
clap_complete::generate(gen, &mut cmd, name, &mut buf);
snapbox::Assert::new()
.action_env("SNAPSHOTS")
.matches_path(expected_path, buf);
}
carapace_spec_clap-0.1.12/tests/snapshots/aliases.yaml 0000644 0000000 0000000 00000000215 10461020230 0021144 0 ustar 0000000 0000000 name: aliases
description: testing bash completions
flags:
-f, --flag: cmd flag
-o, --option=: cmd option
-V, --version: Print version
carapace_spec_clap-0.1.12/tests/snapshots/basic.yaml 0000644 0000000 0000000 00000000214 10461020230 0020603 0 ustar 0000000 0000000 name: basic
description: ''
flags:
-v: ''
persistentflags:
-c: ''
commands:
- name: test
description: Subcommand
flags:
-d*: ''
carapace_spec_clap-0.1.12/tests/snapshots/feature_sample.yaml 0000644 0000000 0000000 00000000367 10461020230 0022527 0 ustar 0000000 0000000 name: feature_sample
description: Tests completions
flags:
-c, --config*: some config file
-V, --version: Print version
commands:
- name: test
description: tests things
flags:
--case=: the case to test
-V, --version: Print version
carapace_spec_clap-0.1.12/tests/snapshots/quoting.yaml 0000644 0000000 0000000 00000001400 10461020230 0021206 0 ustar 0000000 0000000 name: quoting
description: ''
flags:
--backslash: Avoid '/n'
--backticks: For more information see `echo test`
--brackets: List packages [filter]
--double-quotes: Can be "always", "auto", or "never"
--expansions: Execute the shell command with $SHELL
--single-quotes: Can be 'always', 'auto', or 'never'
-V, --version: Print version
commands:
- name: cmd-single-quotes
description: Can be 'always', 'auto', or 'never'
- name: cmd-double-quotes
description: Can be "always", "auto", or "never"
- name: cmd-backticks
description: For more information see `echo test`
- name: cmd-backslash
description: Avoid '/n'
- name: cmd-brackets
description: List packages [filter]
- name: cmd-expansions
description: Execute the shell command with $SHELL
carapace_spec_clap-0.1.12/tests/snapshots/special_commands.yaml 0000644 0000000 0000000 00000000706 10461020230 0023031 0 ustar 0000000 0000000 name: special_commands
description: Tests completions
flags:
-c, --config*: some config file
-V, --version: Print version
commands:
- name: test
description: tests things
flags:
--case=: the case to test
-V, --version: Print version
- name: some_cmd
description: tests other things
flags:
-V, --version: Print version
- name: some-cmd-with-hyphens
aliases:
- hyphen
description: ''
flags:
-V, --version: Print version
carapace_spec_clap-0.1.12/tests/snapshots/sub_subcommands.yaml 0000644 0000000 0000000 00000001075 10461020230 0022714 0 ustar 0000000 0000000 name: sub_subcommands
description: Tests completions
flags:
-c, --config*: some config file
-V, --version: Print version
commands:
- name: test
description: tests things
flags:
--case=: the case to test
-V, --version: Print version
- name: some_cmd
description: top level subcommand
flags:
-V, --version: Print version
commands:
- name: sub_cmd
description: sub-subcommand
flags:
--config=: the other case to test
-V, --version: Print version
completion:
flag:
config:
- Lest quotes aren't escaped.
carapace_spec_clap-0.1.12/tests/snapshots/value_hint.yaml 0000644 0000000 0000000 00000001131 10461020230 0021657 0 ustar 0000000 0000000 name: value_hint
description: ''
flags:
--choice=: ''
-c, --cmd=: ''
--cmd-name=: ''
-d, --dir=: ''
--email=: ''
-e, --exe=: ''
-f, --file=: ''
-H, --host=: ''
--other=: ''
-p, --path=: ''
--unknown=: ''
--url=: ''
-u, --user=: ''
completion:
flag:
choice:
- bash
- fish
- zsh
cmd:
- $_os.PathExecutables
- $files
cmd-name:
- $_os.PathExecutables
- $files
dir:
- $directories
exe:
- $files
file:
- $files
host:
- $_net.Hosts
path:
- $files
user:
- $_os.Users
positionalany:
- TODO