mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
Merge pull request #23 from epage/examples
test: Verify examples based on feature flags
This commit is contained in:
commit
c2c9f0acb1
7 changed files with 42 additions and 29 deletions
|
@ -131,10 +131,16 @@ trycmd = { version = "0.8.0", default-features = false, features = ["color-auto"
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "busybox"
|
name = "busybox"
|
||||||
path = "examples/24a_multicall_busybox.rs"
|
path = "examples/24a_multicall_busybox.rs"
|
||||||
|
required-features = ["unstable-multicall"]
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "hostname"
|
name = "hostname"
|
||||||
path = "examples/24b_multicall_hostname.rs"
|
path = "examples/24b_multicall_hostname.rs"
|
||||||
|
required-features = ["unstable-multicall"]
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "09_cargo_metadata"
|
||||||
|
required-features = ["cargo"]
|
||||||
|
|
||||||
[profile.test]
|
[profile.test]
|
||||||
opt-level = 1
|
opt-level = 1
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -11,7 +11,7 @@ ifneq (${TOOLCHAIN_TARGET},)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
_FEATURES = minimal default wasm full release
|
_FEATURES = minimal default wasm full release
|
||||||
_FEATURES_minimal = --no-default-features --features "std cargo"
|
_FEATURES_minimal = --no-default-features --features "std"
|
||||||
_FEATURES_default =
|
_FEATURES_default =
|
||||||
_FEATURES_wasm = --features "yaml regex unstable-replace unstable-multicall unstable-grouped"
|
_FEATURES_wasm = --features "yaml regex unstable-replace unstable-multicall unstable-grouped"
|
||||||
_FEATURES_full = --features "wrap_help yaml regex unstable-replace unstable-multicall unstable-grouped doc"
|
_FEATURES_full = --features "wrap_help yaml regex unstable-replace unstable-multicall unstable-grouped doc"
|
||||||
|
|
|
@ -4,7 +4,7 @@ See the documentation for clap::AppSettings::Multicall for rationale.
|
||||||
|
|
||||||
This example omits every command except true and false,
|
This example omits every command except true and false,
|
||||||
which are the most trivial to implement,
|
which are the most trivial to implement,
|
||||||
```bash
|
```bash,ignore
|
||||||
$ busybox true
|
$ busybox true
|
||||||
? 0
|
? 0
|
||||||
$ busybox false
|
$ busybox false
|
||||||
|
@ -14,14 +14,14 @@ $ busybox false
|
||||||
|
|
||||||
But includes the `--install` option as an example of why it can be useful
|
But includes the `--install` option as an example of why it can be useful
|
||||||
for the main program to take arguments that aren't applet subcommands.
|
for the main program to take arguments that aren't applet subcommands.
|
||||||
```bash
|
```bash,ignore
|
||||||
$ busybox --install
|
$ busybox --install
|
||||||
? failed
|
? failed
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
Though users must pass something:
|
Though users must pass something:
|
||||||
```bash
|
```bash,ignore
|
||||||
$ busybox
|
$ busybox
|
||||||
? failed
|
? failed
|
||||||
busybox
|
busybox
|
||||||
|
|
|
@ -17,7 +17,6 @@ fn main() {
|
||||||
.subcommand(App::new("true").about("does nothing successfully"))
|
.subcommand(App::new("true").about("does nothing successfully"))
|
||||||
.subcommand(App::new("false").about("does nothing unsuccessfully"));
|
.subcommand(App::new("false").about("does nothing unsuccessfully"));
|
||||||
|
|
||||||
#[cfg(feature = "unstable-multicall")]
|
|
||||||
let app = app.setting(AppSettings::Multicall);
|
let app = app.setting(AppSettings::Multicall);
|
||||||
let matches = app.get_matches();
|
let matches = app.get_matches();
|
||||||
if matches.occurrences_of("install") > 0 {
|
if matches.occurrences_of("install") > 0 {
|
||||||
|
|
|
@ -4,28 +4,8 @@ See the documentation for clap::AppSettings::Multicall for rationale.
|
||||||
|
|
||||||
This example omits the implementation of displaying address config
|
This example omits the implementation of displaying address config
|
||||||
|
|
||||||
```bash
|
```bash,ignore
|
||||||
$ hostname hostname
|
$ hostname
|
||||||
www
|
www
|
||||||
$ hostname dnsdomainname
|
|
||||||
example.com
|
|
||||||
```
|
```
|
||||||
*Note: without the links setup, we can't demonostrate the multicall behavior*
|
*Note: without the links setup, we can't demonostrate the multicall behavior*
|
||||||
|
|
||||||
Though users must pass something:
|
|
||||||
```bash
|
|
||||||
$ hostname
|
|
||||||
? failed
|
|
||||||
hostname
|
|
||||||
|
|
||||||
USAGE:
|
|
||||||
hostname[EXE] [SUBCOMMAND]
|
|
||||||
|
|
||||||
OPTIONS:
|
|
||||||
-h, --help Print help information
|
|
||||||
|
|
||||||
SUBCOMMANDS:
|
|
||||||
dnsdomainname show domain name part of FQDN
|
|
||||||
help Print this message or the help of the given subcommand(s)
|
|
||||||
hostname show hostname part of FQDN
|
|
||||||
```
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ fn main() {
|
||||||
.subcommand(App::new("hostname").about("show hostname part of FQDN"))
|
.subcommand(App::new("hostname").about("show hostname part of FQDN"))
|
||||||
.subcommand(App::new("dnsdomainname").about("show domain name part of FQDN"));
|
.subcommand(App::new("dnsdomainname").about("show domain name part of FQDN"));
|
||||||
|
|
||||||
#[cfg(feature = "unstable-multicall")]
|
|
||||||
let app = app.setting(AppSettings::Multicall);
|
let app = app.setting(AppSettings::Multicall);
|
||||||
|
|
||||||
match app.get_matches().subcommand_name() {
|
match app.get_matches().subcommand_name() {
|
||||||
|
|
|
@ -3,7 +3,36 @@
|
||||||
#[test]
|
#[test]
|
||||||
fn example_tests() {
|
fn example_tests() {
|
||||||
let t = trycmd::TestCases::new();
|
let t = trycmd::TestCases::new();
|
||||||
t.register_bins(trycmd::cargo::compile_examples([]).unwrap());
|
let features = [
|
||||||
|
#[cfg(feature = "debug")]
|
||||||
|
"debug",
|
||||||
|
#[cfg(feature = "doc")]
|
||||||
|
"doc",
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
"std",
|
||||||
|
#[cfg(feature = "derive")]
|
||||||
|
"derive",
|
||||||
|
#[cfg(feature = "cargo")]
|
||||||
|
"cargo",
|
||||||
|
#[cfg(feature = "color")]
|
||||||
|
"color",
|
||||||
|
#[cfg(feature = "env")]
|
||||||
|
"env",
|
||||||
|
#[cfg(feature = "suggestions")]
|
||||||
|
"suggestions",
|
||||||
|
#[cfg(feature = "unicode")]
|
||||||
|
"unicode",
|
||||||
|
#[cfg(feature = "wrap_help")]
|
||||||
|
"wrap_help",
|
||||||
|
#[cfg(feature = "unsable-replace")]
|
||||||
|
"unsable-replace",
|
||||||
|
#[cfg(feature = "unsable-multicall")]
|
||||||
|
"unsable-multicall",
|
||||||
|
#[cfg(feature = "unsable-grouped")]
|
||||||
|
"unsable-grouped",
|
||||||
|
]
|
||||||
|
.join(" ");
|
||||||
|
t.register_bins(trycmd::cargo::compile_examples(["--features", &features]).unwrap());
|
||||||
t.case("examples/*.md");
|
t.case("examples/*.md");
|
||||||
#[cfg(not(feature = "unstable-multicall"))]
|
#[cfg(not(feature = "unstable-multicall"))]
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue