Skip to content

Running examples with required features should be easier #15912

@alice-i-cecile

Description

@alice-i-cecile

Problem

When attempting to run an example that requires additional features, I encounter an error message that looks like:

alice@pop-os:~/Documents/bevy$ cargo run --example solari
error: target `solari` in package `bevy` requires the features: `bevy_solari`, `https`
Consider enabling them by passing, e.g., `--features="bevy_solari https"`

I then copy-paste this incantation into the terminal:

alice@pop-os:~/Documents/bevy$ cargo run --example solari --features="bevy_solari https"

and it now works!

This is a clear and helpful error message, but the process feels needlessly convoluted: cargo already knows what incantation I clearly intended to call!

Proposed Solution

Option 1: Prompt to rerun

Add a y/n prompt when outputting this error message, asking if the user would like to rerun the example with the corresponding features enabled. If yes, do that.

Option 2: --required-features flag

Create a command line flag for cargo run --example --required-features that automatically enables all required features for the example.

Option 3: Quietly do the right thing by default

Always run examples with the required features, logging that such-and-such features were required.

Add a special opt-out if necessary, like --no-required-features.

Notes

As a user, I think that Option 1 is best, followed by Option 3.

  • Option 1: clear, explicit, not too onerous, no magic
  • Option 2: slightly easier to type and less annoying, but why is this not the default?
  • Option 3: very smooth and low friction, but clever in a way that makes me a bit nervous

That said, I am unsure if Cargo supports prompts: Option 1 may not be feasible to implement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cargo-targetsArea: selection and definition of targets (lib, bins, examples, tests, benches)A-required-featuresArea: required-features settingC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions