Skip to content

Is parsing more complex in Clap 3.2? #3839

Answered by epage
steveklabnik asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, that should be using value_parser. It seems a downside to the new approach is the u8 isn't showing up anywhere for inference to determine the type for parse_int, so you need the turbo fish. Unfortunately,. I don't think there is a way to get type inference working.

Working example:

#!/usr/bin/env -S rust-script --debug

//! ```cargo
//! [dependencies]
//! clap = { path = "../clap", features = ["derive"] }
//! parse_int = "*"
//! ```

use clap::{Args, Parser, Subcommand};
use std::path;

#[derive(Debug, Parser)]
struct Cli {
    #[clap(
        long,
        short,
        value_name = "controller",
        value_parser = parse_int::parse::<u8>
    )]
    controller: Option<u8>,
}

fn m…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@steveklabnik
Comment options

@epage
Comment options

Answer selected by steveklabnik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants