reaganmcf / lightmon

A lightweight, cross-platform, language-agnostic "run code on file change" tool, inspired by Nodemon
GNU General Public License v3.0
15 stars 2 forks source link

Allow cargo subcommands (test, doc, fmt, clippy) as cli options for rust configuration #19

Closed reaganmcf closed 3 years ago

reaganmcf commented 3 years ago

Currently, lightmon rust only supports cargo build since that is how cli::build_rust_config() works. But even while working on this project, I want to be able to do cargo test or cargo doc without the shell script method. Being able to pass in the common cargo subcommands would be nice:

$ lightmon rust doc
$ lightmon rust test
reaganmcf commented 3 years ago

Note: We should actually also do some smart resolution here because cargo run makes no sense for libraries.

If src/lib.rs exists, then exec_commands should be cargo test

reaganmcf commented 3 years ago

This is actually kind of tricky because for each subcommand of cargo there are so many flags people probably want to use. Either we can support them, or just tell them to use shell mode.

While I do think that's definitely the solution for very custom usages, I think we should support some popular flags, for example:

build has many popular flags: --lib, --bin name, --features features, --all-features, --release, --target-dir directory, --out-dir directory, etc.

Which ones should we support?

reaganmcf commented 3 years ago

@alayshahh How do you think we should go about supporting the arguments to the subcommands. The linked PR has working subcommands but you can't pass any arguments into it yet, still waiting to figure out how we want to do this.

alayshahh commented 3 years ago

It might be a but difficult without the lightmon.toml file. If we can we can store args for the different cargo sub commands like this. Another adaptation we can have is take anything after the 'lightmon rust' arg and pass it to the command. If no args, we can just default to 'cargo run'

reaganmcf commented 3 years ago

Yea because I don't want to not have some features and would rather have a dynamic way to allow all flags (current and new ones in the future).

For example, running lightmon rust doc --arg1 foo --bar bazz would pass --arg1 foo --bar bazz to cargo doc without us having to specify the arguments explicitly in cli.yaml

reaganmcf commented 3 years ago

@alayshahh The latest commit to the PR fixes this and makes the usage must more expressive and realistic.

Any subcommands after lightmon rust get parsed using clap's AppSetting::ExternalSubcommands global setting. This means the following:

lightmon rust build --bin my_bin --all-targets

Will resolve the exec command as cargo build --bin my_bin --all-targets