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

Allow --features #152

Merged
merged 7 commits into from
Jul 4, 2020
Merged

Allow --features #152

merged 7 commits into from
Jul 4, 2020

Conversation

mulimoen
Copy link
Contributor

Captures --features <features> and passes this to all cargo invocations.

I intentionally left out --no-default-features and --all-features to prevent feature creep. I think the current choice is the most common one, and for more advanced usages the workaround mentioned in #151 could be utilised.

Fixes #151

src/args.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
@mulimoen
Copy link
Contributor Author

The --features feat1 might be wrongly placed if any cargo command is multi-word, but I don't think this can happen. Are there any arguments which might be passed to cargo in addition to the subcommand?

@passcod
Copy link
Member

passcod commented Jun 18, 2020

Yes, there are... but as a first iteration, I think it's fine as is. The implementation can be refined as people complain... if people complain.

@mulimoen
Copy link
Contributor Author

It seems ok to push them to the back anyways. Should only matter when using a combination of other features flags, which are not implemented yet.

@mulimoen
Copy link
Contributor Author

I did file an issue on cargo b --help listing --features as being space separated: rust-lang/cargo#8381

@@ -302,6 +306,16 @@ program instead of cargo:
$ cargo watch -x 'test -- --color=always'
```

### I want to compile my build with additional features

The `--features` flag is recognized and passed to all cargo invocations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry: this is not true anymore :) given the limitations added with your latest changes.

src/lib.rs Outdated
@@ -30,11 +30,29 @@ pub fn change_dir() {
pub fn set_commands(debug: bool, builder: &mut ArgsBuilder, matches: &ArgMatches) {
let mut commands: Vec<String> = Vec::new();

// --features are injected at start of every cargo invocation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this isn't either, given we now push at the end of the commands

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...which... we can't do, as per #151 (comment)

Consider cargo watch --features foo -x 'run -- --options=for --binary': the code as it is now would run cargo run --options=for --binary --features foo which would not have the desired effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would require us to split the first word off the subcommand (if any) and inject --features foo. Will return to the drawing board!

@mulimoen
Copy link
Contributor Author

The features are now injected just after the subcommand. I am not fully confident in the splitting of the words, it will mess up tabs and newlines. Is this a problem?

@passcod
Copy link
Member

passcod commented Jun 21, 2020

Hmm , I wonder if instead you could do a partial parse and split on the first whitespace, then insert in between the pieces

@passcod
Copy link
Member

passcod commented Jun 21, 2020

Looks great! I'll test it out myself tomorrow (it's midnight here!)

@mulimoen
Copy link
Contributor Author

That turned out to be quite easy! Might be subtly wrong when separating with a tab instead of a space, but we are inserting --features there anyway.

For reference: find returns the byte index, and split_at takes a byte offset. This means the splitting is unicode-safe.

@passcod passcod merged commit e131826 into watchexec:main Jul 4, 2020
passcod added a commit that referenced this pull request Jul 4, 2020
@mulimoen mulimoen deleted the features branch August 12, 2020 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow cargo watch --features my_feature
2 participants