Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary CustomCli: clap::Args bound in Cucumber::with_cli() #257

Closed
yds12 opened this issue Feb 15, 2023 · 5 comments
Closed

Unnecessary CustomCli: clap::Args bound in Cucumber::with_cli() #257

yds12 opened this issue Feb 15, 2023 · 5 comments
Assignees
Labels
k::api Related to API (application interface) question Further information is requested

Comments

@yds12
Copy link

yds12 commented Feb 15, 2023

I usually use the Cucumber::with_cli method to configure both the cucumber options (such as --tags and --features) and also custom options. Is there a way to pass these configurations without using a struct that derives clap::Args?

@ilslv
Copy link
Member

ilslv commented Feb 16, 2023

@yds12 Cucumber has a lot of configuration options, for example --tags or --features can be substituted with Cucumber::filter_run_and_exit(). Are there any specific options you are missing?

@yds12
Copy link
Author

yds12 commented Feb 16, 2023

Thanks for the quick feedback @ilslv . In my case, it's not much about any particular option but the Cli config as a whole. The problem I have, to give more context, is that we have a complex setup with a library wrapping cucumber-rs and other binary projects that import that library. Sometimes those projects don't necessarily have clap, but they still might have their own CLI options, so we would benefit if we could pass to cucumber-rs something pretty much identical to the Cli object, but without being an instance of clap::Args. For now what we do is to build this Cli that implement clap::Args manually, but that's far from ideal and sometimes we get strange errors due to clap trying to validate this even though there's no actual CLI being parsed (when deriving clap::Args, the macro generates a lot of code, I think some validation is inserted there).

My understanding is that this is not currently possible, so this issue would be like a feature suggestion (if it fits with the project's goals). But please let me know if I am missing something.

@ilslv
Copy link
Member

ilslv commented Feb 16, 2023

@yds12 as far as I can understand the problem is in CustomCli: clap::Args bound in Cucumber::with_cli(). I'll take a look whether we can relax this bound, but in the meantime you can implement wrapper that will implement empty clap::Args for any type:

use clap::Args;

#[derive(Args, Clone, Copy, Debug)]
#[group(skip)]
struct Empty<T: Default> {
    #[arg(skip)]
    inner: T,
}

@tyranron tyranron added question Further information is requested k::api Related to API (application interface) labels Feb 16, 2023
@yds12
Copy link
Author

yds12 commented Feb 16, 2023

Thanks @ilslv, that helps!

@ilslv ilslv changed the title Configuring without CLI Unnecessary CustomCli: clap::Args bound in Cucumber::with_cli() Feb 16, 2023
@ilslv
Copy link
Member

ilslv commented Feb 16, 2023

This issue originates in clap-rs/clap#3032, so we can't easily remove CustomCli: clap::Args bound.

Theoretically we can try implementing clap::Parser manually on cli::Opts, but this would complicate code a lot and I don't even know whether this trait is stable and suitable for manual implementation. As use-case described in the issue is quite rare and working hack was found, I'm closing this issue for now.

@ilslv ilslv closed this as completed Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
k::api Related to API (application interface) question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants