cucumber-rs / cucumber

Cucumber testing framework for Rust. Fully native, no external test runners or dependencies.
https://cucumber-rs.github.io/cucumber/main
Apache License 2.0
563 stars 69 forks source link

Cucumber ran as library traps over CLI arguments #303

Closed raffaeleragni closed 1 year ago

raffaeleragni commented 1 year ago

I am trying to wrap my own CLI args to extend some extra features, run multiple instances of cucumber, and potentially do also more. I am using clap for my own args, but the problem is as soon as I run cucumber, it also tries to parse the arguments using its own clap defined parser and will stop working saying that arguments are invalid.

Example:

use clap::Parser;
use cucumber::World;

#[derive(World, Debug, Default)]
struct Env;

#[derive(Parser, Debug)]
#[command()]
pub struct Args {
    pub targets: Vec<String>,
    #[arg(long)]
    pub serial: bool,
}

#[tokio::main]
async fn main() {
    let args = Args::parse();
    for target in args.targets {
        Env::run(target).await;
    }
}

./target/debug/test_cuc --serial main.feature

error: unexpected argument '--serial' found

Usage: test_cuc [OPTIONS]

For more information, try '--help'.

I noticed it happens around this place: https://github.com/cucumber-rs/cucumber/blob/main/src/cucumber.rs#L732 Would it be possible to make the that cli parser optional in some way?

tyranron commented 1 year ago

@raffaeleragni yes, of course.

This is described in this chapter of the Book. And also answered here: https://github.com/cucumber-rs/cucumber/discussions/294#discussioncomment-6435194.