mirror of
https://github.com/clap-rs/clap
synced 2024-12-12 05:42:33 +00:00
commit
60aac4760a
44 changed files with 338 additions and 1331 deletions
87
.github/workflows/ci-pr.yml
vendored
87
.github/workflows/ci-pr.yml
vendored
|
@ -1,87 +0,0 @@
|
|||
name: CI-PR
|
||||
on:
|
||||
pull_request:
|
||||
branches: [master]
|
||||
concurrency:
|
||||
group: ci-pr-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
jobs:
|
||||
ci-pr:
|
||||
name: CI-PR
|
||||
needs: [test-minimal, test-full, msrv]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Done
|
||||
run: exit 0
|
||||
test-minimal:
|
||||
name: Tests (Minimal)
|
||||
env:
|
||||
FLAGS: --no-default-features --features 'std cargo'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest]
|
||||
rust: [stable]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Install rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: ${{ matrix.rust }}
|
||||
override: true
|
||||
- name: Cache Builds
|
||||
uses: Swatinem/rust-cache@v1
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Compile
|
||||
run: cargo test --no-run ${{ env.FLAGS }}
|
||||
- name: Test
|
||||
run: cargo test ${{ env.FLAGS }}
|
||||
test-full:
|
||||
name: Tests (Full)
|
||||
env:
|
||||
FLAGS: --features 'wrap_help yaml regex unstable-replace unstable-multicall unstable-grouped'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest]
|
||||
rust: [stable]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Install rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: ${{ matrix.rust }}
|
||||
override: true
|
||||
- name: Cache Builds
|
||||
uses: Swatinem/rust-cache@v1
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Compile
|
||||
run: cargo test --no-run ${{ env.FLAGS }}
|
||||
- name: Test
|
||||
run: cargo test ${{ env.FLAGS }}
|
||||
msrv:
|
||||
name: "Check MSRV: 1.54.0"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Install rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: 1.54.0 # MSRV
|
||||
override: true
|
||||
- name: Cache Builds
|
||||
uses: Swatinem/rust-cache@v1
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Default features
|
||||
run: cargo check --all-targets
|
||||
- name: All features + Debug
|
||||
run: cargo check --all-targets --features "wrap_help yaml regex unstable-replace unstable-multicall unstable-grouped debug"
|
||||
- name: No features
|
||||
run: cargo check --all-targets --no-default-features --features "std cargo"
|
||||
- name: UI Tests
|
||||
run: cargo test --package clap_derive -- ui
|
302
.github/workflows/ci.yml
vendored
302
.github/workflows/ci.yml
vendored
|
@ -1,175 +1,181 @@
|
|||
name: CI
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- '**'
|
||||
- '!/*.md'
|
||||
- '!/docs/**'
|
||||
- "!/LICENSE-*"
|
||||
push:
|
||||
branches: [staging, trying]
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- '**'
|
||||
- '!/*.md'
|
||||
- '!/docs/**'
|
||||
- "!/LICENSE-*"
|
||||
schedule:
|
||||
- cron: '3 3 3 * *'
|
||||
jobs:
|
||||
ci:
|
||||
name: CI
|
||||
needs: [test, wasm]
|
||||
needs: [smoke, test, check, docs, rustfmt, clippy]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Done
|
||||
run: exit 0
|
||||
smoke:
|
||||
name: Quick Check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
profile: minimal
|
||||
override: true
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- name: Default features
|
||||
run: make check-default
|
||||
test:
|
||||
name: Tests
|
||||
name: Test
|
||||
needs: smoke
|
||||
strategy:
|
||||
matrix:
|
||||
build: [linux, windows, mac, minimal, default]
|
||||
include:
|
||||
- build: linux
|
||||
os: ubuntu-latest
|
||||
rust: "stable"
|
||||
features: "full"
|
||||
- build: windows
|
||||
os: windows-latest
|
||||
rust: "stable"
|
||||
features: "full"
|
||||
- build: mac
|
||||
os: macos-latest
|
||||
rust: "stable"
|
||||
features: "full"
|
||||
- build: minimal
|
||||
os: ubuntu-latest
|
||||
rust: "stable"
|
||||
features: "minimal"
|
||||
- build: default
|
||||
os: ubuntu-latest
|
||||
rust: "stable"
|
||||
features: "default"
|
||||
continue-on-error: ${{ matrix.rust != 'stable' }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.rust }}
|
||||
profile: minimal
|
||||
override: true
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- name: Build
|
||||
run: make build-${{matrix.features}}
|
||||
- name: Test
|
||||
run: make test-${{matrix.features}}
|
||||
check:
|
||||
name: Check
|
||||
needs: smoke
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
rust: [1.54.0, stable, beta]
|
||||
os: [windows-latest, macos-latest, ubuntu-latest]
|
||||
target:
|
||||
- i686-pc-windows-msvc
|
||||
- x86_64-pc-windows-msvc
|
||||
- i686-pc-windows-gnu
|
||||
- x86_64-pc-windows-gnu
|
||||
- x86_64-unknown-linux-gnu
|
||||
- i686-unknown-linux-gnu
|
||||
- x86_64-apple-darwin
|
||||
features:
|
||||
- none
|
||||
- all
|
||||
- release
|
||||
exclude:
|
||||
- features: release
|
||||
build: [msrv, wasm, wasm-wasi, debug, release]
|
||||
include:
|
||||
- build: msrv
|
||||
rust: 1.54.0 # MSRV
|
||||
target: x86_64-unknown-linux-gnu
|
||||
features: full
|
||||
- build: wasm
|
||||
rust: stable
|
||||
target: wasm32-unknown-unknown
|
||||
features: wasm
|
||||
- build: wasm-wasi
|
||||
rust: stable
|
||||
target: wasm32-wasi
|
||||
features: wasm
|
||||
- build: debug
|
||||
rust: stable
|
||||
- features: release
|
||||
rust: beta
|
||||
- os: windows-latest
|
||||
target: x86_64-apple-darwin
|
||||
- os: windows-latest
|
||||
target: x86_64-unknown-linux-gnu
|
||||
- os: windows-latest
|
||||
target: i686-unknown-linux-gnu
|
||||
- os: macos-latest
|
||||
target: i686-pc-windows-msvc
|
||||
- os: macos-latest
|
||||
target: x86_64-pc-windows-msvc
|
||||
- os: macos-latest
|
||||
target: i686-pc-windows-gnu
|
||||
- os: macos-latest
|
||||
target: x86_64-pc-windows-gnu
|
||||
- os: macos-latest
|
||||
features: debug
|
||||
- build: release
|
||||
rust: stable
|
||||
target: x86_64-unknown-linux-gnu
|
||||
- os: macos-latest
|
||||
target: i686-unknown-linux-gnu
|
||||
- os: ubuntu-latest
|
||||
target: i686-pc-windows-msvc
|
||||
- os: ubuntu-latest
|
||||
target: x86_64-pc-windows-msvc
|
||||
- os: ubuntu-latest
|
||||
target: i686-pc-windows-gnu
|
||||
- os: ubuntu-latest
|
||||
target: x86_64-pc-windows-gnu
|
||||
- os: ubuntu-latest
|
||||
target: x86_64-apple-darwin
|
||||
runs-on: ${{ matrix.os }}
|
||||
features: release
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Install rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: ${{ matrix.rust }}
|
||||
target: ${{ matrix.target }}
|
||||
override: true
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Install linker
|
||||
if: matrix.target == 'i686-pc-windows-gnu'
|
||||
uses: egor-tensin/setup-mingw@v2
|
||||
with:
|
||||
platform: x86
|
||||
- name: Install linker
|
||||
if: matrix.target == 'x86_64-pc-windows-gnu'
|
||||
uses: egor-tensin/setup-mingw@v2
|
||||
- name: Install linker
|
||||
if: matrix.target == 'i686-unknown-linux-gnu'
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install gcc-multilib
|
||||
- name: Test almost no features
|
||||
uses: actions-rs/cargo@v1
|
||||
if: matrix.features == 'none'
|
||||
with:
|
||||
command: test
|
||||
args: --target ${{ matrix.target }} --no-default-features --features "std cargo" -p clap:3.0.0-beta.5
|
||||
- name: Test all features
|
||||
uses: actions-rs/cargo@v1
|
||||
if: matrix.features == 'all'
|
||||
with:
|
||||
command: test
|
||||
args: --target ${{ matrix.target }} --features "wrap_help yaml regex unstable-replace unstable-multicall unstable-grouped"
|
||||
- name: Check debug
|
||||
uses: actions-rs/cargo@v1
|
||||
if: matrix.features == 'all'
|
||||
with:
|
||||
command: check
|
||||
args: --target ${{ matrix.target }} --features "wrap_help yaml regex unstable-replace unstable-multicall unstable-grouped debug"
|
||||
- name: Test release
|
||||
uses: actions-rs/cargo@v1
|
||||
if: matrix.features == 'release'
|
||||
with:
|
||||
command: test
|
||||
args: --target ${{ matrix.target }} --features "wrap_help yaml regex unstable-replace unstable-multicall unstable-grouped" --release
|
||||
nightly:
|
||||
name: Nightly Tests
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
features:
|
||||
- none
|
||||
- all
|
||||
- release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Install rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: nightly
|
||||
override: true
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Test almost no features
|
||||
uses: actions-rs/cargo@v1
|
||||
if: matrix.features == 'none'
|
||||
with:
|
||||
command: test
|
||||
args: --no-default-features --features "std cargo" -p clap:3.0.0-beta.5
|
||||
- name: Test all features
|
||||
uses: actions-rs/cargo@v1
|
||||
if: matrix.features == 'all'
|
||||
with:
|
||||
command: test
|
||||
args: --features "wrap_help yaml regex unstable-replace unstable-multicall unstable-grouped"
|
||||
- name: Check debug
|
||||
uses: actions-rs/cargo@v1
|
||||
if: matrix.features == 'all'
|
||||
with:
|
||||
command: check
|
||||
args: --features "wrap_help yaml regex unstable-replace unstable-multicall unstable-grouped debug"
|
||||
- name: Test release
|
||||
uses: actions-rs/cargo@v1
|
||||
if: matrix.features == 'release'
|
||||
with:
|
||||
command: test
|
||||
args: --features "wrap_help yaml regex unstable-replace unstable-multicall unstable-grouped" --release
|
||||
wasm:
|
||||
name: Wasm Check
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
target: [wasm32-unknown-unknown, wasm32-wasi]
|
||||
steps:
|
||||
- name: Install rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: 1.54.0
|
||||
target: ${{ matrix.target }}
|
||||
override: true
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Check
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: check
|
||||
args: --target ${{ matrix.target }} --features "yaml regex unstable-replace unstable-multicall unstable-grouped"
|
||||
run: make check-${{ matrix.features }}
|
||||
docs:
|
||||
name: Docs
|
||||
needs: smoke
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
profile: minimal
|
||||
override: true
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- name: Check documentation
|
||||
env:
|
||||
RUSTDOCFLAGS: -D warnings
|
||||
run: cargo doc --workspace --all-features --no-deps --document-private-items
|
||||
rustfmt:
|
||||
name: rustfmt
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
# Not MSRV because its harder to jump between versions and people are
|
||||
# more likely to have stable
|
||||
toolchain: stable
|
||||
profile: minimal
|
||||
override: true
|
||||
components: rustfmt
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- name: Check formatting
|
||||
run: cargo fmt --all -- --check
|
||||
clippy:
|
||||
name: clippy
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: 1.54.0 # MSRV
|
||||
profile: minimal
|
||||
override: true
|
||||
components: clippy
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- uses: actions-rs/clippy-check@v1
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
args: --workspace --all-features --all-targets -- -D warnings
|
||||
|
|
39
.github/workflows/coverage.yml
vendored
39
.github/workflows/coverage.yml
vendored
|
@ -1,39 +0,0 @@
|
|||
name: Coverage
|
||||
on:
|
||||
pull_request:
|
||||
branches: [master]
|
||||
push:
|
||||
branches: [master]
|
||||
concurrency:
|
||||
group: coverage-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
jobs:
|
||||
coverage:
|
||||
name: Coverage
|
||||
continue-on-error: true
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Install rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: nightly
|
||||
components: llvm-tools-preview
|
||||
override: true
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Install llvm-cov
|
||||
uses: actions-rs/install@v0.1
|
||||
with:
|
||||
crate: cargo-llvm-cov
|
||||
version: 0.1.0-alpha.4
|
||||
use-tool-cache: true
|
||||
- name: Coverage
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: llvm-cov
|
||||
args: --features "wrap_help yaml regex unstable-replace unstable-multicall unstable-grouped" --lcov --output-path lcov.info
|
||||
- name: Coveralls
|
||||
uses: coverallsapp/github-action@master
|
||||
with:
|
||||
path-to-lcov: lcov.info
|
||||
github-token: ${{ secrets.github_token }}
|
40
.github/workflows/lint.yml
vendored
40
.github/workflows/lint.yml
vendored
|
@ -1,40 +0,0 @@
|
|||
name: Lint
|
||||
on:
|
||||
pull_request:
|
||||
branches: [master]
|
||||
push:
|
||||
branches: [staging, trying]
|
||||
concurrency:
|
||||
group: lint-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
jobs:
|
||||
lint:
|
||||
name: Lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Install rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: stable
|
||||
override: true
|
||||
components: rustfmt, clippy
|
||||
- name: Cache Builds
|
||||
uses: Swatinem/rust-cache@v1
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Clippy for almost no features
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: clippy
|
||||
args: --no-default-features --features "std cargo"
|
||||
- name: Clippy for all features
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: clippy
|
||||
args: --features "wrap_help yaml regex unstable-replace unstable-multicall unstable-grouped" -- -D warnings
|
||||
- name: Format check
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: fmt
|
||||
args: -- --check
|
101
.github/workflows/rust-next.yml
vendored
Normal file
101
.github/workflows/rust-next.yml
vendored
Normal file
|
@ -0,0 +1,101 @@
|
|||
name: rust-next
|
||||
on:
|
||||
schedule:
|
||||
- cron: '3 3 3 * *'
|
||||
jobs:
|
||||
test:
|
||||
name: Test
|
||||
strategy:
|
||||
matrix:
|
||||
build: [linux, windows, mac, beta, nightly, minimal, default]
|
||||
include:
|
||||
- build: linux
|
||||
os: ubuntu-latest
|
||||
rust: "stable"
|
||||
features: "full"
|
||||
- build: windows
|
||||
os: windows-latest
|
||||
rust: "stable"
|
||||
features: "full"
|
||||
- build: mac
|
||||
os: macos-latest
|
||||
rust: "stable"
|
||||
features: "full"
|
||||
- build: beta
|
||||
os: ubuntu-latest
|
||||
rust: "beta"
|
||||
features: "full"
|
||||
- build: nightly
|
||||
os: ubuntu-latest
|
||||
rust: "nightly"
|
||||
features: "full"
|
||||
- build: minimal
|
||||
os: ubuntu-latest
|
||||
rust: "stable"
|
||||
features: "minimal"
|
||||
- build: default
|
||||
os: ubuntu-latest
|
||||
rust: "stable"
|
||||
features: "default"
|
||||
continue-on-error: ${{ matrix.rust != 'stable' }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.rust }}
|
||||
profile: minimal
|
||||
override: true
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- name: Build
|
||||
run: make build-${{matrix.features}}
|
||||
- name: Test
|
||||
run: make test-${{matrix.features}}
|
||||
rustfmt:
|
||||
name: rustfmt
|
||||
strategy:
|
||||
matrix:
|
||||
rust:
|
||||
- stable
|
||||
- beta
|
||||
continue-on-error: ${{ matrix.rust != 'stable' }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.rust }}
|
||||
profile: minimal
|
||||
override: true
|
||||
components: rustfmt
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- name: Check formatting
|
||||
run: cargo fmt --all -- --check
|
||||
clippy:
|
||||
name: clippy
|
||||
strategy:
|
||||
matrix:
|
||||
rust:
|
||||
- 1.54.0 # MSRV
|
||||
- stable
|
||||
continue-on-error: ${{ matrix.rust != '1.54.0' }} # MSRV
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: ${{ matrix.rust }}
|
||||
profile: minimal
|
||||
override: true
|
||||
components: clippy
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
- uses: actions-rs/clippy-check@v1
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
args: --workspace --all-features --all-targets -- -D warnings
|
28
.github/workflows/site.yml
vendored
28
.github/workflows/site.yml
vendored
|
@ -1,28 +0,0 @@
|
|||
name: Site
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
paths:
|
||||
- site/**
|
||||
- .github/workflows/site.yml
|
||||
concurrency:
|
||||
group: site
|
||||
cancel-in-progress: true
|
||||
jobs:
|
||||
site:
|
||||
name: Deploy site
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Build
|
||||
uses: shalzz/zola-deploy-action@v0.14.1
|
||||
env:
|
||||
BUILD_DIR: site
|
||||
BUILD_ONLY: true
|
||||
- name: Deploy
|
||||
if: ${{ success() }}
|
||||
uses: JamesIves/github-pages-deploy-action@4.1.5
|
||||
with:
|
||||
branch: gh-pages
|
||||
folder: site/public
|
|
@ -136,11 +136,4 @@ members = [
|
|||
"clap_derive",
|
||||
"clap_generate",
|
||||
"clap_generate_fig",
|
||||
"clap_up",
|
||||
]
|
||||
default-members = [
|
||||
".",
|
||||
"clap_derive",
|
||||
"clap_generate",
|
||||
"clap_generate_fig",
|
||||
]
|
||||
|
|
28
Makefile
Normal file
28
Makefile
Normal file
|
@ -0,0 +1,28 @@
|
|||
# CI Steps
|
||||
#
|
||||
# Considerations
|
||||
# - Easy to debug: show the command being run
|
||||
# - Leverage CI features: Only run individual steps so we can use features like reporting elapsed time per step
|
||||
|
||||
ARGS?=
|
||||
TOOLCHAIN_TARGET ?=
|
||||
ifneq (${TOOLCHAIN_TARGET},)
|
||||
ARGS+=--target ${TOOLCHAIN_TARGET}
|
||||
endif
|
||||
|
||||
_FEATURES = minimal default wasm full release
|
||||
_FEATURES_minimal = --no-default-features --features "std cargo"
|
||||
_FEATURES_default =
|
||||
_FEATURES_wasm = --features "yaml regex unstable-replace unstable-multicall unstable-grouped"
|
||||
_FEATURES_full = --features "wrap_help yaml regex unstable-replace unstable-multicall unstable-grouped"
|
||||
_FEATURES_debug = ${_FEATURES_full} --features debug
|
||||
_FEATURES_release = ${_FEATURES_full} --release
|
||||
|
||||
check-%:
|
||||
cargo check --all-targets ${ARGS} ${_FEATURES_${@:check-%=%}}
|
||||
|
||||
build-%:
|
||||
cargo test --no-run ${ARGS} ${_FEATURES_${@:build-%=%}}
|
||||
|
||||
test-%:
|
||||
cargo test ${ARGS} ${_FEATURES_${@:test-%=%}}
|
11
bors.toml
11
bors.toml
|
@ -1,11 +0,0 @@
|
|||
status = [
|
||||
"CI",
|
||||
]
|
||||
pr_status = [
|
||||
"CI-PR", "Lint",
|
||||
]
|
||||
timeout_sec = 7200
|
||||
prerun_timeout_sec = 7200
|
||||
delete_merged_branches = true
|
||||
cut_body_after = ""
|
||||
block_labels = ["M: blocked", "M: require changes"]
|
|
@ -239,7 +239,7 @@ fn alias() {
|
|||
#[derive(ArgEnum, PartialEq, Debug, Clone)]
|
||||
enum ArgChoice {
|
||||
#[clap(alias = "TOTP")]
|
||||
TOTP,
|
||||
Totp,
|
||||
}
|
||||
|
||||
#[derive(Parser, PartialEq, Debug)]
|
||||
|
@ -250,13 +250,13 @@ fn alias() {
|
|||
|
||||
assert_eq!(
|
||||
Opt {
|
||||
arg: ArgChoice::TOTP
|
||||
arg: ArgChoice::Totp
|
||||
},
|
||||
Opt::try_parse_from(&["", "totp"]).unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
Opt {
|
||||
arg: ArgChoice::TOTP
|
||||
arg: ArgChoice::Totp
|
||||
},
|
||||
Opt::try_parse_from(&["", "TOTP"]).unwrap()
|
||||
);
|
||||
|
@ -267,7 +267,7 @@ fn multiple_alias() {
|
|||
#[derive(ArgEnum, PartialEq, Debug, Clone)]
|
||||
enum ArgChoice {
|
||||
#[clap(alias = "TOTP", alias = "t")]
|
||||
TOTP,
|
||||
Totp,
|
||||
}
|
||||
|
||||
#[derive(Parser, PartialEq, Debug)]
|
||||
|
@ -278,19 +278,19 @@ fn multiple_alias() {
|
|||
|
||||
assert_eq!(
|
||||
Opt {
|
||||
arg: ArgChoice::TOTP
|
||||
arg: ArgChoice::Totp
|
||||
},
|
||||
Opt::try_parse_from(&["", "totp"]).unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
Opt {
|
||||
arg: ArgChoice::TOTP
|
||||
arg: ArgChoice::Totp
|
||||
},
|
||||
Opt::try_parse_from(&["", "TOTP"]).unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
Opt {
|
||||
arg: ArgChoice::TOTP
|
||||
arg: ArgChoice::Totp
|
||||
},
|
||||
Opt::try_parse_from(&["", "t"]).unwrap()
|
||||
);
|
||||
|
|
|
@ -60,6 +60,9 @@ fn app_help_heading_applied() {
|
|||
|
||||
#[test]
|
||||
fn app_help_heading_flattened() {
|
||||
// Used to help track the cause in tests
|
||||
#![allow(clippy::enum_variant_names)]
|
||||
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
struct CliOptions {
|
||||
#[clap(flatten)]
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
[package]
|
||||
name = "clap_up"
|
||||
version = "0.0.0"
|
||||
edition = "2018"
|
||||
authors = [
|
||||
"Pavan Kumar Sunkara <pavan.sss1991@gmail.com>",
|
||||
"Clap Maintainers",
|
||||
]
|
||||
description = "Automatic code upgrader for Clap"
|
||||
repository = "https://github.com/clap-rs/clap/tree/master/clap_up"
|
||||
homepage = "https://clap.rs/"
|
||||
keywords = [
|
||||
"clap",
|
||||
"cli",
|
||||
"upgrader",
|
||||
"cargo-up",
|
||||
]
|
||||
categories = []
|
||||
license = "MIT OR Apache-2.0"
|
||||
readme = "README.md"
|
||||
|
||||
[lib]
|
||||
bench = false
|
||||
|
||||
[dependencies]
|
||||
cargo-up = { version = "=0.0.4" }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[package.metadata.workspaces]
|
||||
independent = true
|
|
@ -1,201 +0,0 @@
|
|||
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 [yyyy] [name of copyright owner]
|
||||
|
||||
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.
|
|
@ -1,21 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-2016 Kevin B. Knapp
|
||||
|
||||
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.
|
|
@ -1,13 +0,0 @@
|
|||
# clap_up
|
||||
|
||||
Automatic code upgrader for [clap](https://docs.rs/clap) (using tool [cargo-up](https://github.com/pksunkara/cargo-up))
|
||||
|
||||
### Usage
|
||||
|
||||
```
|
||||
cargo install cargo-up --features cli --no-default-features
|
||||
```
|
||||
|
||||
```
|
||||
cargo up dep clap
|
||||
```
|
|
@ -1,166 +0,0 @@
|
|||
use cargo_up::{
|
||||
ra_ap_syntax::{
|
||||
ast::{ArgListOwner, CallExpr},
|
||||
AstNode,
|
||||
},
|
||||
Runner, Version,
|
||||
};
|
||||
|
||||
pub fn runner() -> Runner {
|
||||
Runner::new()
|
||||
.minimum("2.33.0")
|
||||
.unwrap()
|
||||
.version(
|
||||
Version::new("3.0.0-rc.0")
|
||||
.unwrap()
|
||||
.peers(&["structopt"])
|
||||
// .replace_dep("structopt", "clap", features = ["derive"])
|
||||
.rename_structs("clap::args::subcommand", &[["SubCommand", "App"]])
|
||||
.rename_methods(
|
||||
"structopt::StructOpt",
|
||||
&[
|
||||
["from_args", "parse"],
|
||||
["from_iter", "parse_from"],
|
||||
["from_iter_safe", "try_parse_from"],
|
||||
["from_clap", "from_arg_matches"],
|
||||
["clap", "into_app"],
|
||||
],
|
||||
)
|
||||
.rename_variants(
|
||||
"clap::errors::ErrorKind",
|
||||
&[
|
||||
["HelpDisplayed", "DisplayHelp"],
|
||||
["VersionDisplayed", "DisplayVersion"],
|
||||
[
|
||||
"MissingArgumentOrSubcommand",
|
||||
"DisplayHelpOnMissingArgumentOrSubcommand",
|
||||
],
|
||||
],
|
||||
)
|
||||
.rename_variants(
|
||||
"clap::app::settings::AppSettings",
|
||||
&[
|
||||
["DisableHelpFlags", "DisableHelpFlag"],
|
||||
["DisableVersion", "DisableVersionFlag"],
|
||||
// @TODO @v3 should be removed, not renamed
|
||||
["VersionlessSubcommands", "DisableVersionForSubcommands"],
|
||||
],
|
||||
)
|
||||
.rename_variants(
|
||||
"clap::args::settings::ArgSettings",
|
||||
&[
|
||||
["CaseInsensitive", "IgnoreCase"],
|
||||
["AllowLeadingHyphen", "AllowHyphenValues"],
|
||||
["EmptyValues", "AllowEmptyValues"],
|
||||
],
|
||||
)
|
||||
.rename_methods(
|
||||
"clap::app::App",
|
||||
&[
|
||||
["from_yaml", "from"],
|
||||
["arg_from_usage", "arg"],
|
||||
["args_from_usage", "args"],
|
||||
["help", "override_help"],
|
||||
["usage", "override_usage"],
|
||||
["template", "help_template"],
|
||||
["get_matches_safe", "try_get_matches"],
|
||||
["get_matches_from_safe", "try_get_matches_from"],
|
||||
["get_matches_from_safe_borrow", "try_get_matches_from_mut"],
|
||||
["set_term_width", "term_width"],
|
||||
["with_defaults", "new"],
|
||||
["version_message", "mut_arg"],
|
||||
["version_short", "mut_arg"],
|
||||
["help_message", "mut_arg"],
|
||||
["help_short", "mut_arg"],
|
||||
["generate_usage", "render_usage"],
|
||||
],
|
||||
)
|
||||
.rename_methods(
|
||||
"clap::args::arg::Arg",
|
||||
&[
|
||||
["help", "about"],
|
||||
["from_usage", "from"],
|
||||
["set", "setting"],
|
||||
["unset", "unset_setting"],
|
||||
["from_yaml", "from"],
|
||||
["with_name", "new"],
|
||||
["required_if", "required_if_eq"],
|
||||
["required_ifs", "required_if_eq_any"],
|
||||
["required_unless", "required_unless_present"],
|
||||
["required_unless_one", "required_unless_present_any"],
|
||||
["required_unless_all", "required_unless_present_all"],
|
||||
],
|
||||
)
|
||||
.rename_methods(
|
||||
"clap::args::group::ArgGroup",
|
||||
&[["from_yaml", "from"], ["with_name", "new"]],
|
||||
)
|
||||
.rename_methods(
|
||||
"clap::args::subcommand::SubCommand",
|
||||
&[["from_yaml", "from"], ["with_name", "new"]],
|
||||
)
|
||||
.rename_members("clap::errors::Error", &[["message", "cause"]]) // TODO: check
|
||||
.hook_method_call_expr_on("clap::app::App", "args_from_usage", |u, n, _| {
|
||||
let arg = n.arg_list().unwrap().args().last();
|
||||
|
||||
u.insert(
|
||||
arg.unwrap().syntax().text_range().end(),
|
||||
".lines().map(|l| l.trim()).filter(|l| !l.is_empty())",
|
||||
);
|
||||
})
|
||||
.hook_path_expr_on("clap::app::App", "with_defaults", |u, n, _| {
|
||||
if let Some(parent) = n.syntax().parent() {
|
||||
if let Some(call_expr) = CallExpr::cast(parent) {
|
||||
// TODO: Add full path
|
||||
u.insert(
|
||||
call_expr.syntax().text_range().end(),
|
||||
".author(crate_authors!()).version(crate_version!())",
|
||||
);
|
||||
}
|
||||
}
|
||||
})
|
||||
.hook_method_call_expr_on("clap::app::App", "version_message", |u, n, _| {
|
||||
let arg_list = n.arg_list().unwrap();
|
||||
|
||||
u.insert(
|
||||
arg_list.l_paren_token().unwrap().text_range().end(),
|
||||
"\"version\", |a| a.about(",
|
||||
);
|
||||
u.insert(arg_list.r_paren_token().unwrap().text_range().start(), ")")
|
||||
})
|
||||
.hook_method_call_expr_on("clap::app::App", "version_short", |u, n, _| {
|
||||
let arg_list = n.arg_list().unwrap();
|
||||
|
||||
u.insert(
|
||||
arg_list.l_paren_token().unwrap().text_range().end(),
|
||||
"\"version\", |a| a.short(",
|
||||
);
|
||||
u.insert(
|
||||
arg_list.r_paren_token().unwrap().text_range().start(),
|
||||
".trim_start_matches(|c| c == '-').chars().nth(0).unwrap_or('V'))",
|
||||
)
|
||||
})
|
||||
.hook_method_call_expr_on("clap::app::App", "help_message", |u, n, _| {
|
||||
let arg_list = n.arg_list().unwrap();
|
||||
|
||||
u.insert(
|
||||
arg_list.l_paren_token().unwrap().text_range().end(),
|
||||
"\"help\", |a| a.about(",
|
||||
);
|
||||
u.insert(arg_list.r_paren_token().unwrap().text_range().start(), ")")
|
||||
})
|
||||
.hook_method_call_expr_on("clap::app::App", "help_short", |u, n, _| {
|
||||
let arg_list = n.arg_list().unwrap();
|
||||
|
||||
u.insert(
|
||||
arg_list.l_paren_token().unwrap().text_range().end(),
|
||||
"\"help\", |a| a.short(",
|
||||
);
|
||||
u.insert(
|
||||
arg_list.r_paren_token().unwrap().text_range().start(),
|
||||
".trim_start_matches(|c| c == '-').chars().nth(0).unwrap_or('h'))",
|
||||
)
|
||||
}),
|
||||
)
|
||||
.version(Version::new("3.0.0").unwrap())
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
IFS=$'\n'
|
||||
|
||||
touch .tmp.out
|
||||
|
||||
echo -n "Testing"
|
||||
for TEST in $(find tests/ -type f -name "*.rs" -exec basename {} .rs \;); do
|
||||
echo -n "."
|
||||
echo -n -e "$TEST:\t" >> .tmp.out
|
||||
cargo test --test $TEST 2>&1 | grep -o -e '[0-9]* failed;' >> .tmp.out
|
||||
done
|
||||
|
||||
echo "Done"
|
||||
column -t < .tmp.out
|
||||
rm .tmp.out
|
||||
unset IFS
|
1
site/.gitignore
vendored
1
site/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
public
|
|
@ -1,14 +0,0 @@
|
|||
base_url = "https://clap.rs"
|
||||
|
||||
title = "Clap"
|
||||
description = "Fast & Modern CLI Framework for Rust"
|
||||
|
||||
build_search_index = true
|
||||
|
||||
default_language = "en"
|
||||
|
||||
[markdown]
|
||||
highlight_code = true
|
||||
highlight_theme = "ayu-dark"
|
||||
|
||||
external_links_target_blank = true
|
|
@ -1,58 +0,0 @@
|
|||
+++
|
||||
title = "Fast & Modern CLI Framework for Rust"
|
||||
+++
|
||||
|
||||
**Clap** is a simple-to-use, efficient, and full-featured library for parsing command line arguments and subcommands when writing console/terminal applications.
|
||||
|
||||
Here is an example of a simple program:
|
||||
|
||||
```rust
|
||||
use clap::Parser;
|
||||
|
||||
/// Simple program to greet a person
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(name = "hello")]
|
||||
struct Hello {
|
||||
/// Name of the person to greet
|
||||
#[clap(short, long)]
|
||||
name: String,
|
||||
|
||||
/// Number of times to greet
|
||||
#[clap(short, long, default_value = "1")]
|
||||
count: u8,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let hello = Hello::parse();
|
||||
|
||||
for _ in 0..hello.count {
|
||||
println!("Hello {}!", hello.name)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The above example program can be run as shown below:
|
||||
|
||||
```
|
||||
$ hello --name John --count 3
|
||||
Hello John!
|
||||
Hello John!
|
||||
Hello John!
|
||||
```
|
||||
|
||||
The program also has an automatically generated help message:
|
||||
|
||||
```
|
||||
hello
|
||||
|
||||
Simple program to greet a person
|
||||
|
||||
USAGE:
|
||||
hello [OPTIONS] --name <name>
|
||||
|
||||
OPTIONS:
|
||||
-c, --count <count> Number of times to greet [default: 1]
|
||||
-h, --help Print help information
|
||||
-n, --name <name> Name of the person to greet
|
||||
-V, --version Print version information
|
||||
```
|
|
@ -1,5 +0,0 @@
|
|||
+++
|
||||
title = "Cheatsheet"
|
||||
+++
|
||||
|
||||
Work in progress...
|
|
@ -1,5 +0,0 @@
|
|||
+++
|
||||
title = "Cookbook"
|
||||
+++
|
||||
|
||||
Work in progress...
|
|
@ -1 +0,0 @@
|
|||
clap.rs
|
|
@ -1,185 +0,0 @@
|
|||
html {
|
||||
background: #211f1a;
|
||||
color: #f5f5f5;
|
||||
font-size: 16px;
|
||||
font-family: 'Raleway', sans-serif;
|
||||
}
|
||||
|
||||
.maxview {
|
||||
max-width: 1440px;
|
||||
width: 100%;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.maxview article, .maxview section {
|
||||
max-width: 1200px;
|
||||
width: 100%;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
header {
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
justify-content: space-between;
|
||||
padding: 1.5rem 2.5rem;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
nav {
|
||||
padding: 1.25rem 0;
|
||||
}
|
||||
|
||||
nav a {
|
||||
font-size: 20px;
|
||||
line-height: 50px;
|
||||
margin-left: 1.25rem;
|
||||
}
|
||||
|
||||
nav a:hover, nav a:focus {
|
||||
border-bottom: 1px dashed rgb(255,168,106);
|
||||
}
|
||||
|
||||
#nav-btn, #nav-check {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
header {
|
||||
padding: 0 0 1.5rem;
|
||||
}
|
||||
|
||||
#nav-btn {
|
||||
display: inline-block;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
#nav-btn label {
|
||||
display: inline-block;
|
||||
width: 50px;
|
||||
height: 46px;
|
||||
padding: 1.5rem 1.25rem 1rem;
|
||||
}
|
||||
|
||||
#nav-btn span {
|
||||
display: block;
|
||||
width: 50px;
|
||||
height: 16px;
|
||||
border-top: 2px solid rgb(255, 168, 106);
|
||||
}
|
||||
|
||||
.nav {
|
||||
position: absolute;
|
||||
display: block;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
height: 0;
|
||||
transition: all 0.3s ease-in;
|
||||
overflow-y: hidden;
|
||||
top: 90px;
|
||||
left: 0px;
|
||||
padding: 0;
|
||||
background: #FBF5F3;
|
||||
}
|
||||
|
||||
nav a {
|
||||
display: block;
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#nav-check:not(:checked) ~ .nav {
|
||||
height: 0px;
|
||||
}
|
||||
|
||||
#nav-check:checked ~ .nav {
|
||||
height: auto;
|
||||
overflow-y: auto;
|
||||
}
|
||||
}
|
||||
|
||||
footer {
|
||||
text-align: center;
|
||||
padding: 2.5rem 0;
|
||||
background: #211f1a;
|
||||
color: rgba(255, 168, 106, .7);
|
||||
}
|
||||
|
||||
footer a, #content a {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#content {
|
||||
padding: 1.25rem 2.5rem 3rem;
|
||||
min-height: calc(100vh - 10.5rem - 18px - 50px);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
pre {
|
||||
font-family: 'Raleway', monospace;
|
||||
font-size: 0.9rem;
|
||||
line-height: 1.2rem;
|
||||
padding: 1.5rem;
|
||||
margin-bottom: 30px;
|
||||
overflow-x:auto;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
#content {
|
||||
padding: 1.25rem 0.5rem 3rem;
|
||||
width: 100% !important;
|
||||
}
|
||||
}
|
||||
|
||||
a {
|
||||
color: rgb(255, 168, 106);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
p {
|
||||
margin-bottom: 30px;
|
||||
line-height: 30px;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4 {
|
||||
margin-bottom: 20px;
|
||||
font-family: 'Lato', sans-serif;
|
||||
color: rgb(255, 168, 106);
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2.5rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1.75rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
h4 {
|
||||
font-size: 1rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.anchor {
|
||||
font-weight: 300 !important;
|
||||
opacity: 0.75;
|
||||
font-size: 1.75rem;
|
||||
}
|
||||
|
||||
.anchor.level-3 {
|
||||
font-size: 1.25rem;
|
||||
margin: 0 0.25rem;
|
||||
}
|
||||
|
||||
.anchor.level-4 {
|
||||
font-size: 1rem;
|
||||
margin: 0 0.375rem;
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 49 KiB |
|
@ -1,3 +0,0 @@
|
|||
<script>
|
||||
window.location = '{{ config.base_url | safe }}';
|
||||
</script>
|
|
@ -1 +0,0 @@
|
|||
<a href="#{{ id }}" class="anchor level-{{ level }}">#</a>
|
|
@ -1,15 +0,0 @@
|
|||
{% extends "shared/base.html" %}
|
||||
|
||||
{% block title %}{{ section.title }}{% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
{% include "shared/header.html" %}
|
||||
|
||||
<main id="content" class="maxview">
|
||||
<article>
|
||||
<h1 class="post-title">{{ section.title }}</h1>
|
||||
|
||||
{{ section.content | safe }}
|
||||
</article>
|
||||
</main>
|
||||
{% endblock content %}
|
|
@ -1,15 +0,0 @@
|
|||
{% extends "shared/base.html" %}
|
||||
|
||||
{% block title %}{{ page.title }}{% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
{% include "shared/header.html" %}
|
||||
|
||||
<main id="content" class="maxview">
|
||||
<article>
|
||||
<h1 class="post-title">{{ page.title }}</h1>
|
||||
|
||||
{{ page.content | safe }}
|
||||
</article>
|
||||
</main>
|
||||
{% endblock content %}
|
|
@ -1,43 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="{{ lang }}">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="Content-Language" content="{{ lang }}" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="HandheldFriendly" content="True" />
|
||||
<meta name="MobileOptimized" content="320" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
|
||||
<title>{{ config.title }} · {% block title %}{% endblock title %}</title>
|
||||
|
||||
<meta name="description" content="{{ config.description }}" />
|
||||
|
||||
<link href="{{ config.base_url | safe }}/atom.xml" rel="alternate" type="application/atom+xml" title="{{ config.title }}" />
|
||||
|
||||
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
|
||||
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<link rel="canonical" href="{{ current_url | safe }}" />
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/pure/2.0.3/base.min.css" integrity="sha512-AdMpi0OeNfx52R5VxegHFzDqd3HcfbRITcA1PwibceRawcsRM1grQbHrFA3SJ73oilitvIgw1jl0y7AbOySm5g==" crossorigin="anonymous" />
|
||||
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css2?family=Lato:wght@300;400;700;900&family=Raleway:wght@400&display=swap">
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="{{ config.base_url | safe }}/css/app.css">
|
||||
|
||||
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||
|
||||
<script type="text/javascript" src="{{ config.base_url | safe }}/js/app.js"></script>
|
||||
|
||||
{% block head %}{% endblock head %}
|
||||
</head>
|
||||
<body>
|
||||
{% block content %}{% endblock content %}
|
||||
|
||||
<footer>
|
||||
<section>© {{ config.title }}. All rights reserved. Powered by <a href="http://getzola.org" target="_blank">Zola</a>.</section>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
|
@ -1,12 +0,0 @@
|
|||
<header class="maxview">
|
||||
<input type="checkbox" id="nav-check" />
|
||||
|
||||
{% include "shared/logo.html" %}
|
||||
|
||||
<nav class="nav">
|
||||
<a href="/cheatsheet">Cheatsheet</a>
|
||||
<a href="/cookbook">Cookbook</a>
|
||||
<a href="https://docs.rs/clap" target="_blank">Reference</a>
|
||||
<a href="https://github.com/clap-rs/clap" target="_blank">Code</a>
|
||||
</nav>
|
||||
</header>
|
|
@ -1,13 +0,0 @@
|
|||
<div>
|
||||
<a href="/" id="logo">
|
||||
<img src="{{ config.base_url | safe }}/images/media/clap.png" width="90" height="90"></img>
|
||||
</a>
|
||||
|
||||
<div id="nav-btn">
|
||||
<label for="nav-check">
|
||||
<span></span>
|
||||
<span></span>
|
||||
<span></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
|
@ -2754,7 +2754,7 @@ impl<'help> App<'help> {
|
|||
}
|
||||
|
||||
/// A workaround:
|
||||
/// https://github.com/rust-lang/rust/issues/34511#issuecomment-373423999
|
||||
/// <https://github.com/rust-lang/rust/issues/34511#issuecomment-373423999>
|
||||
pub(crate) trait Captures<'a> {}
|
||||
impl<'a, T> Captures<'a> for T {}
|
||||
|
||||
|
|
|
@ -163,10 +163,10 @@ impl_settings! { AppSettings, AppFlags,
|
|||
/// [`App`]: crate::App
|
||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||
pub enum AppSettings {
|
||||
/// Deprecated, this is now the default, see [`AppSettings::AllowInvalidUtf8ForExternalSubcommands`] and [`ArgSettings::AllowInvalidUtf8ForExternalSubcommands`] for the opposite.
|
||||
/// Deprecated, this is now the default, see [`AppSettings::AllowInvalidUtf8ForExternalSubcommands`] and [`ArgSettings::AllowInvalidUtf8`][crate::ArgSettings::AllowInvalidUtf8] for the opposite.
|
||||
#[deprecated(
|
||||
since = "3.0.0",
|
||||
note = "This is now the default see [`AppSettings::AllowInvalidUtf8ForExternalSubcommands`] and [`ArgSettings::AllowInvalidUtf8ForExternalSubcommands`] for the opposite."
|
||||
note = "This is now the default see `AppSettings::AllowInvalidUtf8ForExternalSubcommands` and `ArgSettings::AllowInvalidUtf8` for the opposite."
|
||||
)]
|
||||
StrictUtf8,
|
||||
|
||||
|
@ -515,15 +515,15 @@ pub enum AppSettings {
|
|||
#[deprecated(since = "3.0.0", note = "This is now the default")]
|
||||
ColoredHelp,
|
||||
|
||||
/// Deprecated, see [`App::color`]
|
||||
/// Deprecated, see [`App::color`][crate::App::color]
|
||||
#[deprecated(since = "3.0.0", note = "Replaced with `App::color`")]
|
||||
ColorAuto,
|
||||
|
||||
/// Deprecated, see [`App::color`]
|
||||
/// Deprecated, see [`App::color`][crate::App::color]
|
||||
#[deprecated(since = "3.0.0", note = "Replaced with `App::color`")]
|
||||
ColorAlways,
|
||||
|
||||
/// Deprecated, see [`App::color`]
|
||||
/// Deprecated, see [`App::color`][crate::App::color]
|
||||
#[deprecated(since = "3.0.0", note = "Replaced with `App::color`")]
|
||||
ColorNever,
|
||||
|
||||
|
@ -637,7 +637,7 @@ pub enum AppSettings {
|
|||
/// [`subcommands`]: crate::App::subcommand()
|
||||
DeriveDisplayOrder,
|
||||
|
||||
/// Parse the bin name (argv[0]) as a subcommand
|
||||
/// Parse the bin name (`argv[0]`) as a subcommand
|
||||
///
|
||||
/// This adds a small performance penalty to startup
|
||||
/// as it requires comparing the bin name against every subcommand name.
|
||||
|
|
|
@ -617,8 +617,6 @@ macro_rules! wlnerr {
|
|||
#[cfg(feature = "debug")]
|
||||
macro_rules! debug {
|
||||
($($arg:tt)*) => ({
|
||||
// The `print!` line will make clippy complain about duplicates.
|
||||
#[allow(clippy::branches_sharing_code)]
|
||||
print!("[{:>w$}] \t", module_path!(), w = 28);
|
||||
println!($($arg)*);
|
||||
})
|
||||
|
@ -629,7 +627,7 @@ macro_rules! debug {
|
|||
($($arg:tt)*) => {};
|
||||
}
|
||||
|
||||
/// Deprecated, see [`ArgMatches::value_of_t`]
|
||||
/// Deprecated, see [`ArgMatches::value_of_t`][crate::ArgMatches::value_of_t]
|
||||
#[macro_export]
|
||||
#[deprecated(since = "3.0.0", note = "Replaced with `ArgMatches::value_of_t`")]
|
||||
macro_rules! value_t {
|
||||
|
@ -641,7 +639,7 @@ macro_rules! value_t {
|
|||
};
|
||||
}
|
||||
|
||||
/// Deprecated, see [`ArgMatches::value_of_t_or_exit`]
|
||||
/// Deprecated, see [`ArgMatches::value_of_t_or_exit`][crate::ArgMatches::value_of_t_or_exit]
|
||||
#[macro_export]
|
||||
#[deprecated(
|
||||
since = "3.0.0",
|
||||
|
@ -656,7 +654,7 @@ macro_rules! value_t_or_exit {
|
|||
};
|
||||
}
|
||||
|
||||
/// Deprecated, see [`ArgMatches::values_of_t`]
|
||||
/// Deprecated, see [`ArgMatches::values_of_t`][crate::ArgMatches::value_of_t]
|
||||
#[macro_export]
|
||||
#[deprecated(since = "3.0.0", note = "Replaced with `ArgMatches::values_of_t`")]
|
||||
macro_rules! values_t {
|
||||
|
@ -668,7 +666,7 @@ macro_rules! values_t {
|
|||
};
|
||||
}
|
||||
|
||||
/// Deprecated, see [`ArgMatches::values_of_t_or_exit`]
|
||||
/// Deprecated, see [`ArgMatches::values_of_t_or_exit`][crate::ArgMatches::value_of_t_or_exit]
|
||||
#[macro_export]
|
||||
#[deprecated(
|
||||
since = "3.0.0",
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#![cfg(feature = "cargo")]
|
||||
|
||||
use clap::{app_from_crate, ErrorKind};
|
||||
|
||||
static EVERYTHING: &str = "clap {{version}}
|
||||
|
|
|
@ -1162,17 +1162,17 @@ fn no_auto_help() {
|
|||
.setting(AppSettings::NoAutoHelp)
|
||||
.subcommand(App::new("foo"));
|
||||
|
||||
let result = app.clone().try_get_matches_from("myprog --help".split(" "));
|
||||
let result = app.clone().try_get_matches_from("myprog --help".split(' '));
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert!(result.unwrap().is_present("help"));
|
||||
|
||||
let result = app.clone().try_get_matches_from("myprog -h".split(" "));
|
||||
let result = app.clone().try_get_matches_from("myprog -h".split(' '));
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert!(result.unwrap().is_present("help"));
|
||||
|
||||
let result = app.clone().try_get_matches_from("myprog help".split(" "));
|
||||
let result = app.clone().try_get_matches_from("myprog help".split(' '));
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert_eq!(result.unwrap().subcommand_name(), Some("help"));
|
||||
|
@ -1186,12 +1186,12 @@ fn no_auto_version() {
|
|||
|
||||
let result = app
|
||||
.clone()
|
||||
.try_get_matches_from("myprog --version".split(" "));
|
||||
.try_get_matches_from("myprog --version".split(' '));
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert!(result.unwrap().is_present("version"));
|
||||
|
||||
let result = app.clone().try_get_matches_from("myprog -V".split(" "));
|
||||
let result = app.clone().try_get_matches_from("myprog -V".split(' '));
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert!(result.unwrap().is_present("version"));
|
||||
|
@ -1206,12 +1206,12 @@ fn no_auto_version_mut_arg() {
|
|||
|
||||
let result = app
|
||||
.clone()
|
||||
.try_get_matches_from("myprog --version".split(" "));
|
||||
.try_get_matches_from("myprog --version".split(' '));
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert!(result.unwrap().is_present("version"));
|
||||
|
||||
let result = app.clone().try_get_matches_from("myprog -V".split(" "));
|
||||
let result = app.clone().try_get_matches_from("myprog -V".split(' '));
|
||||
|
||||
assert!(result.is_ok());
|
||||
assert!(result.unwrap().is_present("version"));
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#![cfg(feature = "cargo")]
|
||||
|
||||
use clap::{crate_authors, crate_description, crate_name, crate_version, App, ErrorKind};
|
||||
|
||||
static DESCRIPTION_ONLY: &str = "prog 1
|
||||
|
|
|
@ -37,13 +37,13 @@ fn examples_are_functional() {
|
|||
#[cfg(not(feature = "unstable-multicall"))]
|
||||
continue;
|
||||
#[allow(unreachable_code)]
|
||||
"busybox".into()
|
||||
"busybox"
|
||||
}
|
||||
Some("24b_multicall_hostname.rs") => {
|
||||
#[cfg(not(feature = "unstable-multicall"))]
|
||||
continue;
|
||||
#[allow(unreachable_code)]
|
||||
"hostname".into()
|
||||
"hostname"
|
||||
}
|
||||
_ => path
|
||||
.file_stem()
|
||||
|
|
|
@ -2608,7 +2608,7 @@ fn disabled_help_flag() {
|
|||
let res = App::new("foo")
|
||||
.subcommand(App::new("sub"))
|
||||
.setting(AppSettings::DisableHelpFlag)
|
||||
.try_get_matches_from("foo a".split(" "));
|
||||
.try_get_matches_from("foo a".split(' '));
|
||||
assert!(res.is_err());
|
||||
let err = res.unwrap_err();
|
||||
assert_eq!(err.kind, ErrorKind::UnrecognizedSubcommand);
|
||||
|
@ -2621,7 +2621,7 @@ fn disabled_help_flag_and_subcommand() {
|
|||
.subcommand(App::new("sub"))
|
||||
.setting(AppSettings::DisableHelpFlag)
|
||||
.setting(AppSettings::DisableHelpSubcommand)
|
||||
.try_get_matches_from("foo help".split(" "));
|
||||
.try_get_matches_from("foo help".split(' '));
|
||||
assert!(res.is_err());
|
||||
let err = res.unwrap_err();
|
||||
assert_eq!(err.kind, ErrorKind::UnrecognizedSubcommand);
|
||||
|
|
|
@ -22,7 +22,7 @@ fn with_subcommand() -> App<'static> {
|
|||
|
||||
#[test]
|
||||
fn no_version_flag_short() {
|
||||
let res = common().try_get_matches_from("foo -V".split(" "));
|
||||
let res = common().try_get_matches_from("foo -V".split(' '));
|
||||
|
||||
assert!(res.is_err());
|
||||
let err = res.unwrap_err();
|
||||
|
@ -32,7 +32,7 @@ fn no_version_flag_short() {
|
|||
|
||||
#[test]
|
||||
fn no_version_flag_long() {
|
||||
let res = common().try_get_matches_from("foo --version".split(" "));
|
||||
let res = common().try_get_matches_from("foo --version".split(' '));
|
||||
|
||||
assert!(res.is_err());
|
||||
let err = res.unwrap_err();
|
||||
|
@ -42,7 +42,7 @@ fn no_version_flag_long() {
|
|||
|
||||
#[test]
|
||||
fn version_flag_from_version_short() {
|
||||
let res = with_version().try_get_matches_from("foo -V".split(" "));
|
||||
let res = with_version().try_get_matches_from("foo -V".split(' '));
|
||||
|
||||
assert!(res.is_err());
|
||||
let err = res.unwrap_err();
|
||||
|
@ -52,7 +52,7 @@ fn version_flag_from_version_short() {
|
|||
|
||||
#[test]
|
||||
fn version_flag_from_version_long() {
|
||||
let res = with_version().try_get_matches_from("foo --version".split(" "));
|
||||
let res = with_version().try_get_matches_from("foo --version".split(' '));
|
||||
|
||||
assert!(res.is_err());
|
||||
let err = res.unwrap_err();
|
||||
|
@ -62,7 +62,7 @@ fn version_flag_from_version_long() {
|
|||
|
||||
#[test]
|
||||
fn version_flag_from_long_version_short() {
|
||||
let res = with_long_version().try_get_matches_from("foo -V".split(" "));
|
||||
let res = with_long_version().try_get_matches_from("foo -V".split(' '));
|
||||
|
||||
assert!(res.is_err());
|
||||
let err = res.unwrap_err();
|
||||
|
@ -72,7 +72,7 @@ fn version_flag_from_long_version_short() {
|
|||
|
||||
#[test]
|
||||
fn version_flag_from_long_version_long() {
|
||||
let res = with_long_version().try_get_matches_from("foo --version".split(" "));
|
||||
let res = with_long_version().try_get_matches_from("foo --version".split(' '));
|
||||
|
||||
assert!(res.is_err());
|
||||
let err = res.unwrap_err();
|
||||
|
@ -84,7 +84,7 @@ fn version_flag_from_long_version_long() {
|
|||
fn override_version_long_with_user_flag() {
|
||||
let res = with_version()
|
||||
.arg(Arg::new("ver").long("version"))
|
||||
.try_get_matches_from("foo --version".split(" "));
|
||||
.try_get_matches_from("foo --version".split(' '));
|
||||
|
||||
assert!(res.is_ok());
|
||||
let m = res.unwrap();
|
||||
|
@ -95,7 +95,7 @@ fn override_version_long_with_user_flag() {
|
|||
fn override_version_long_with_user_flag_no_version_flag() {
|
||||
let res = with_version()
|
||||
.arg(Arg::new("ver").long("version"))
|
||||
.try_get_matches_from("foo -V".split(" "));
|
||||
.try_get_matches_from("foo -V".split(' '));
|
||||
|
||||
assert!(res.is_err());
|
||||
let err = res.unwrap_err();
|
||||
|
@ -106,7 +106,7 @@ fn override_version_long_with_user_flag_no_version_flag() {
|
|||
fn override_version_short_with_user_flag() {
|
||||
let res = with_version()
|
||||
.arg(Arg::new("ver").short('V'))
|
||||
.try_get_matches_from("foo -V".split(" "));
|
||||
.try_get_matches_from("foo -V".split(' '));
|
||||
|
||||
assert!(res.is_ok());
|
||||
let m = res.unwrap();
|
||||
|
@ -117,7 +117,7 @@ fn override_version_short_with_user_flag() {
|
|||
fn override_version_short_with_user_flag_long_still_works() {
|
||||
let res = with_version()
|
||||
.arg(Arg::new("ver").short('V'))
|
||||
.try_get_matches_from("foo --version".split(" "));
|
||||
.try_get_matches_from("foo --version".split(' '));
|
||||
|
||||
assert!(res.is_err());
|
||||
let err = res.unwrap_err();
|
||||
|
@ -128,7 +128,7 @@ fn override_version_short_with_user_flag_long_still_works() {
|
|||
fn mut_version_short() {
|
||||
let res = with_version()
|
||||
.mut_arg("version", |a| a.short('z'))
|
||||
.try_get_matches_from("foo -z".split(" "));
|
||||
.try_get_matches_from("foo -z".split(' '));
|
||||
|
||||
assert!(res.is_err());
|
||||
let err = res.unwrap_err();
|
||||
|
@ -139,7 +139,7 @@ fn mut_version_short() {
|
|||
fn mut_version_long() {
|
||||
let res = with_version()
|
||||
.mut_arg("version", |a| a.long("qux"))
|
||||
.try_get_matches_from("foo --qux".split(" "));
|
||||
.try_get_matches_from("foo --qux".split(' '));
|
||||
|
||||
assert!(res.is_err());
|
||||
let err = res.unwrap_err();
|
||||
|
@ -173,7 +173,7 @@ fn version_about_multi_subcmd() {
|
|||
#[test]
|
||||
fn no_propagation_by_default_long() {
|
||||
// Version Flag should not be propagated to subcommands
|
||||
let res = with_subcommand().try_get_matches_from("foo bar --version".split(" "));
|
||||
let res = with_subcommand().try_get_matches_from("foo bar --version".split(' '));
|
||||
|
||||
assert!(res.is_err());
|
||||
let err = res.unwrap_err();
|
||||
|
@ -183,7 +183,7 @@ fn no_propagation_by_default_long() {
|
|||
|
||||
#[test]
|
||||
fn no_propagation_by_default_short() {
|
||||
let res = with_subcommand().try_get_matches_from("foo bar -V".split(" "));
|
||||
let res = with_subcommand().try_get_matches_from("foo bar -V".split(' '));
|
||||
|
||||
assert!(res.is_err());
|
||||
let err = res.unwrap_err();
|
||||
|
@ -195,7 +195,7 @@ fn no_propagation_by_default_short() {
|
|||
fn propagate_version_long() {
|
||||
let res = with_subcommand()
|
||||
.setting(AppSettings::PropagateVersion)
|
||||
.try_get_matches_from("foo bar --version".split(" "));
|
||||
.try_get_matches_from("foo bar --version".split(' '));
|
||||
|
||||
assert!(res.is_err());
|
||||
let err = res.unwrap_err();
|
||||
|
@ -206,7 +206,7 @@ fn propagate_version_long() {
|
|||
fn propagate_version_short() {
|
||||
let res = with_subcommand()
|
||||
.setting(AppSettings::PropagateVersion)
|
||||
.try_get_matches_from("foo bar -V".split(" "));
|
||||
.try_get_matches_from("foo bar -V".split(' '));
|
||||
|
||||
assert!(res.is_err());
|
||||
let err = res.unwrap_err();
|
||||
|
@ -219,7 +219,7 @@ fn propagate_version_short() {
|
|||
fn mut_arg_version_panic() {
|
||||
let _res = common()
|
||||
.mut_arg("version", |v| v.short('z'))
|
||||
.try_get_matches_from("foo -z".split(" "));
|
||||
.try_get_matches_from("foo -z".split(' '));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -227,7 +227,7 @@ fn mut_arg_version_no_auto_version() {
|
|||
let res = common()
|
||||
.mut_arg("version", |v| v.short('z'))
|
||||
.setting(AppSettings::NoAutoVersion)
|
||||
.try_get_matches_from("foo -z".split(" "));
|
||||
.try_get_matches_from("foo -z".split(' '));
|
||||
|
||||
assert!(res.is_ok());
|
||||
assert!(res.unwrap().is_present("version"));
|
||||
|
@ -240,5 +240,5 @@ fn propagate_version_no_version_info() {
|
|||
let _res = common()
|
||||
.setting(AppSettings::PropagateVersion)
|
||||
.subcommand(App::new("bar"))
|
||||
.try_get_matches_from("foo".split(" "));
|
||||
.try_get_matches_from("foo".split(' '));
|
||||
}
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
# Flags
|
||||
|
||||
-f?
|
||||
-f*
|
||||
-f{$0,3}: flags can't be required by default, hence always 0 or more (bounded/unbounded)
|
||||
|
||||
# Options
|
||||
|
||||
-o val
|
||||
-o val?
|
||||
-o val*
|
||||
-o val+
|
||||
-o val{0,3}
|
||||
|
||||
(-o val){0,3}
|
||||
(-o val?){0,3}
|
||||
(-o val*){0,3}
|
||||
(-o val+){0,3}
|
||||
(-o val{0,3}){0,3}
|
|
@ -1,81 +0,0 @@
|
|||
These are cases which could be detected by `clap`, and potentially warn at compile time. Maybe even with a nice web URL to more info.
|
||||
|
||||
# Abrv. Syntax
|
||||
|
||||
First, a little about the syntax to understand the setup of rule. This syntax will make each rule more concise so we don't have to write an entire `clap` definition.
|
||||
|
||||
## Arg Types
|
||||
|
||||
* `--opt` is an option
|
||||
* `--flag` is a flag
|
||||
* `#` (i.e. `1` or `2`) is a positional argument
|
||||
* `val` is an option value
|
||||
|
||||
## Modifiers
|
||||
|
||||
Can be used on `val` or Arg types
|
||||
|
||||
* `*`: zero or more
|
||||
* `+`: one or more
|
||||
* `?`: zero or one
|
||||
* `{#,#}`: # to # times (i.e. `{1,4}` is one to four times)
|
||||
* `<>`: required
|
||||
* `=`: requires equals
|
||||
* Ends in `,`: requires delimiter
|
||||
* `(foo,bar)`: values can only be `foo` or `bar`
|
||||
|
||||
# --opt val? 1
|
||||
|
||||
## Ambiguous Uses
|
||||
|
||||
```
|
||||
$ prog --opt foo
|
||||
# is foo option val or positional?
|
||||
```
|
||||
|
||||
## Non-Ambiguous Uses
|
||||
|
||||
```
|
||||
$ prog 1 --opt
|
||||
$ prog --opt -- 1
|
||||
```
|
||||
|
||||
## Fixes
|
||||
|
||||
### Require equals on `--opt`
|
||||
|
||||
```
|
||||
$ prog --opt foo
|
||||
# foo is positional
|
||||
|
||||
$ prog --opt=val foo
|
||||
```
|
||||
|
||||
# --opt val+ 1
|
||||
|
||||
## Ambiguous Uses
|
||||
|
||||
```
|
||||
$ prog --opt foo bar
|
||||
# is bar option val or positional?
|
||||
```
|
||||
|
||||
## Non-Ambiguous Uses
|
||||
|
||||
```
|
||||
$ prog 1 --opt val
|
||||
$ prog --opt val -- 1
|
||||
```
|
||||
|
||||
## Fixes
|
||||
|
||||
### `--opt` only one val per occurrence
|
||||
|
||||
```
|
||||
$ prog --opt foo bar
|
||||
# bar is positional
|
||||
|
||||
$ prog --opt val bar --opt foo
|
||||
# bar is positional
|
||||
```
|
||||
|
Loading…
Reference in a new issue