-
Notifications
You must be signed in to change notification settings - Fork 1.4k
PNA Rust, Building Blocks 1 - External exercise reference is incompatible with latest Clap version #471
Copy link
Copy link
Open
Description
The external article referenced in the "Building Blocks" section of the first project is no longer compatible with the latest version of the crate used in the exercise.
As a result, the code example from the article cannot be followed completely anymore. The reason is that YAML is no longer supported by clap for loading commands, as explained in the crate's own documentation.
I attempted to reproduce an equivalent result using the Derive API from the latest version of clap.
clap = { version = "4.5.53", features = ["derive"] }
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(name = "Meow")]
#[command(version = "1.0")]
#[command(about = "Does awesome things")]
struct Cli {
/// Sets a custom config file
#[arg(short, long)]
config: Option<String>,
/// The input file to use
input: String,
/// Sets the level of verbosity
#[arg(short, long)]
verbose: Option<bool>,
#[command(subcommand)]
commands: Option<Commands>,
}
#[derive(Subcommand)]
enum Commands {
/// Controls testing features
Test {
#[arg(short, long)]
debug: Option<bool>,
},
}
fn main() {
let _cli = Cli::parse();
}cargo run -- helpDoes awesome things
Usage: meow [OPTIONS] <INPUT> [COMMAND]
Commands:
test Controls testing features
help Print this message or the help of the given subcommand(s)
Arguments:
<INPUT> The input file to use
Options:
-c, --config <CONFIG> Sets a custom config file
-v, --verbose <VERBOSE> Sets the level of verbosity [possible values: true, false]
-h, --help Print help
-V, --version Print version
It may be helpful to mention on the page that the part of the article relying on clap is out of date.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels