fixup! Make hostname a non-derive example and rename via Cargo.toml

This commit is contained in:
Richard Maw 2021-10-12 19:57:32 +01:00
parent b808729bbc
commit 694329b363
6 changed files with 41 additions and 30 deletions

View file

@ -81,6 +81,14 @@ lazy_static = "1"
version-sync = "0.9"
criterion = "0.3.2"
[[example]]
name = "busybox"
path = "examples/24a_multicall_busybox.rs"
[[example]]
name = "hostname"
path = "examples/24b_multicall_hostname.rs"
[features]
default = [
"std",

View file

@ -38,7 +38,7 @@ heck = "0.3.0"
proc-macro-error = "1"
[dev-dependencies]
clap = { path = "../", features = ["unstable-multicall"] }
clap = { path = "../" }
clap_generate = { path = "../clap_generate" }
trybuild = "1.0"
rustversion = "1"

View file

@ -1,24 +0,0 @@
//! Example of `hostname`-style multicall program
//!
//! See the documentation for clap::AppSettings::Multicall for rationale.
//!
//! This example omits the implementation of displaying address config.
use clap::Parser;
#[derive(Parser, Debug)]
#[clap(name = env!("CARGO_CRATE_NAME"), setting = clap::AppSettings::Multicall)]
enum Args {
/// Show the configured hostname
Hostname,
/// Show the domain name part of the configured hostname
#[clap(about = "show domain")]
DNSDomainName,
}
fn main() {
match Args::parse() {
Args::Hostname => println!("www"),
Args::DNSDomainName => println!("example.com"),
}
}

View file

@ -0,0 +1,23 @@
//! Example of a `hostname-style` multicall program
//!
//! See the documentation for clap::AppSettings::Multicall for rationale.
//!
//! This example omits the implementation of displaying address config
use std::process::exit;
use clap::{App, AppSettings};
fn main() {
let app = App::new(env!("CARGO_CRATE_NAME"))
.setting(AppSettings::ArgRequiredElseHelp)
.setting(AppSettings::Multicall)
.subcommand(App::new("hostname").about("shot hostname part of FQDN"))
.subcommand(App::new("dnsdomainname").about("show domain name part of FQDN"));
match app.get_matches().subcommand_name() {
Some("hostname") => println!("www"),
Some("dnsdomainname") => println!("example.com"),
_ => exit(127),
}
}

View file

@ -10,7 +10,7 @@ fn run_example<S: AsRef<str>>(name: S, args: &[&str]) -> Output {
"--example",
name.as_ref(),
"--features",
"yaml",
"yaml unstable-multicall",
"--",
];
all_args.extend_from_slice(args);
@ -32,10 +32,14 @@ fn examples_are_functional() {
for path in example_paths {
example_count += 1;
let example_name = path
.file_stem()
.and_then(OsStr::to_str)
.expect("unable to determine example name");
let example_name = match path.file_name().and_then(OsStr::to_str) {
Some("24a_multicall_busybox.rs") => "busybox".into(),
Some("24b_multicall_hostname.rs") => "hostname".into(),
_ => path
.file_stem()
.and_then(OsStr::to_str)
.expect("unable to determine example name"),
};
let help_output = run_example(example_name, &["--help"]);
assert!(