forked from extern/nushell
439889dcef
This commit adds the ability to work on features behind a feature flag that won't be included in normal builds of nu. These features are not exposed as Cargo features, as they reflect incomplete features that are not yet stable. To create a feature, add it to `features.toml`: ```toml [hintsv1] description = "Adding hints based on error states in the highlighter" enabled = false ``` Each feature in `features.toml` becomes a feature flag accessible to `cfg`: ```rs println!("hintsv1 is enabled"); ``` By default, features are enabled based on the value of the `enabled` field. You can also enable a feature from the command line via the `NUSHELL_ENABLE_FLAGS` environment variable: ```sh $ NUSHELL_ENABLE_FLAGS=hintsv1 cargo run ``` You can enable all flags via `NUSHELL_ENABLE_ALL_FLAGS`. This commit also updates the CI setup to run the build with all flags off and with all flags on. It also extracts the linting test into its own parallelizable test, which means it doesn't need to run together with every other test anymore. When working on a feature, you should also add tests behind the same flag. A commit is mergable if all tests pass with and without the flag, allowing incomplete commits to land on master as long as the incomplete code builds and passes tests.
59 lines
1.5 KiB
Rust
59 lines
1.5 KiB
Rust
use clap::{App, Arg};
|
|
use log::LevelFilter;
|
|
use std::error::Error;
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
#[cfg(feature1)]
|
|
println!("feature1 is enabled");
|
|
|
|
let matches = App::new("nushell")
|
|
.version(clap::crate_version!())
|
|
.arg(
|
|
Arg::with_name("loglevel")
|
|
.short("l")
|
|
.long("loglevel")
|
|
.value_name("LEVEL")
|
|
.possible_values(&["error", "warn", "info", "debug", "trace"])
|
|
.takes_value(true),
|
|
)
|
|
.arg(
|
|
Arg::with_name("develop")
|
|
.long("develop")
|
|
.multiple(true)
|
|
.takes_value(true),
|
|
)
|
|
.get_matches();
|
|
|
|
let loglevel = match matches.value_of("loglevel") {
|
|
None => LevelFilter::Warn,
|
|
Some("error") => LevelFilter::Error,
|
|
Some("warn") => LevelFilter::Warn,
|
|
Some("info") => LevelFilter::Info,
|
|
Some("debug") => LevelFilter::Debug,
|
|
Some("trace") => LevelFilter::Trace,
|
|
_ => unreachable!(),
|
|
};
|
|
|
|
let mut builder = pretty_env_logger::formatted_builder();
|
|
|
|
if let Ok(s) = std::env::var("RUST_LOG") {
|
|
builder.parse_filters(&s);
|
|
}
|
|
|
|
builder.filter_module("nu", loglevel);
|
|
|
|
match matches.values_of("develop") {
|
|
None => {}
|
|
Some(values) => {
|
|
for item in values {
|
|
builder.filter_module(&format!("nu::{}", item), LevelFilter::Trace);
|
|
}
|
|
}
|
|
}
|
|
|
|
builder.try_init()?;
|
|
|
|
futures::executor::block_on(nu::cli())?;
|
|
Ok(())
|
|
}
|