惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
罗磊的独立博客
量子位
Microsoft Azure Blog
Microsoft Azure Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks
M
MIT News - Artificial intelligence
月光博客
月光博客
IT之家
IT之家
D
DataBreaches.Net
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Last Week in AI
Last Week in AI
D
Docker
The GitHub Blog
The GitHub Blog
B
Blog
V
Visual Studio Blog
博客园 - Franky
N
Netflix TechBlog - Medium
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
博客园 - 聂微东
U
Unit 42

The Rust Programming Language Forum - Latest posts

What's everyone working on this week (21/2026)? Rust Function Call with one Param Iced + Canvas + Text: How do I create a style for canvas text "Value dropped while borrowed" as a lifetime mismatch Weird `use of moved value` behaviour Slightly surprising behavior of a while loop Clap: how to disable options after a certain positional argument How do i tell rust-analyzer what kind of bracket to use for a macro? Iterator + Borrow Checker: Work around borrowing already borrowed mutable variable Requesting data via mavlink SKILLS.md for Rust development 🧵 Stringlet UTF-8 Hack Option Niche? Iterator + Map - How do divide every element, including the last element, by the last element Why can't we store returned value of a function in a variable if one of the parameters goes out of scope My first crate :D, floop: A more convenient and less error prone replacement for loop `{ select! { .. }}` Sorting is slow because architectures are wrong — zan-sort redesigns the architecture, not the algorithm Iced Font - Create a custom monospace font to display dollar amounts Is the UnsafePinned RFC wrong about being able to return `&mut T` from `get_mut_unchecked`? Fixing Polars 0.37 compilation errors: Hashbrown 0.17 dependency conflict and decimal parsing Any plans for improving error diagnostic in Rust 2.0? How do I build completely offline? Is `&mut T -> &mut ManuallyDrop<T>` well-defined and sound? Would you use this? — fixtura, declarative fake data injection for tests Foreign trait restrictions on native types make generics hard to use Cargo Exclude Directive Compiler reasoning around a modulo counter Multiple mutable references to elements within one vector Handling non-`Send` data in a `Send` closure Review: Static Multi Pool Allocator Rmquickjs - High-level MicroQuickJS bindings for Rust
Clap completion question
manfredlotz · 2026-04-17 · via The Rust Programming Language Forum - Latest posts

Let's say I have a program claptest like this:

Test program for clap --ignore flag and shell completion

Usage: claptest [OPTIONS]

Options:
      --ignore <IGNORE>...
          Comma-separated list of things to ignore: blabla, something, other
          
          [possible values: blabla, something, other]

      --completion <SHELL>
          Generate shell completion script and print to stdout.
          
          Examples: claptest --completion fish > ~/.config/fish/completions/claptest.fish claptest --completion bash > ~/.bash_completion.d/claptest claptest --completion zsh  > ~/.zsh/completions/_claptest
          
          [possible values: bash, elvish, fish, powershell, zsh]

  -h, --help
          Print help (see a summary with '-h')

I like to have completion for a call to claptest like this claptest --ignore blabla,something
I get completion only for one of blabla, something or `other'

Here my source

use std::io;

use clap::{CommandFactory, Parser, ValueEnum};
use clap_complete::{Shell, generate};

// ── Ignore values ─────────────────────────────────────────────────────────────

#[derive(Debug, Clone, ValueEnum, PartialEq)]
enum Ignore {
    Blabla,
    Something,
    Other,
}

// ── CLI definition ────────────────────────────────────────────────────────────

#[derive(Parser, Debug)]
#[command(
    name = "claptest",
    about = "Test program for clap --ignore flag and shell completion"
)]
struct Args {
    /// Comma-separated list of things to ignore: blabla, something, other
    #[arg(long, value_delimiter = ',', num_args = 1..)]
    ignore: Vec<Ignore>,

    /// Generate shell completion script and print to stdout.
    ///
    /// Examples:
    ///   claptest --completion fish > ~/.config/fish/completions/claptest.fish
    ///   claptest --completion bash > ~/.bash_completion.d/claptest
    ///   claptest --completion zsh  > ~/.zsh/completions/_claptest
    #[arg(long, value_name = "SHELL")]
    completion: Option<Shell>,
}

// ── Main ──────────────────────────────────────────────────────────────────────

fn main() {
    let args = Args::parse();

    if let Some(shell) = args.completion {
        let mut cmd = Args::command();
        generate(shell, &mut cmd, "claptest", &mut io::stdout());
        return;
    }

    println!(
        "ignore_dupes:      {}",
        args.ignore.contains(&Ignore::Blabla)
    );
    println!(
        "ignore_same_named: {}",
        args.ignore.contains(&Ignore::Something)
    );
    println!(
        "ignore_tmpfiles:   {}",
        args.ignore.contains(&Ignore::Other)
    );
}

Any help appreciated.