-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2817: Add support for Multicall executables as subcommands with a Multicall setting r=pksunkara a=fishface60 Co-authored-by: Richard Maw <richard.maw@gmail.com>
- Loading branch information
Showing
13 changed files
with
309 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//! Example of a `busybox-style` multicall program | ||
//! | ||
//! See the documentation for clap::AppSettings::Multicall for rationale. | ||
//! | ||
//! This example omits every command except true and false, | ||
//! which are the most trivial to implement, | ||
//! 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. | ||
|
||
use std::process::exit; | ||
|
||
use clap::{App, AppSettings, Arg}; | ||
|
||
fn main() { | ||
let app = App::new(env!("CARGO_CRATE_NAME")) | ||
.setting(AppSettings::ArgRequiredElseHelp) | ||
.arg( | ||
Arg::new("install") | ||
.long("install") | ||
.about("Install hardlinks for all subcommands in path") | ||
.exclusive(true) | ||
.takes_value(true) | ||
.default_missing_value("/usr/local/bin") | ||
.use_delimiter(false), | ||
) | ||
.subcommand(App::new("true").about("does nothing successfully")) | ||
.subcommand(App::new("false").about("does nothing unsuccessfully")); | ||
|
||
#[cfg(feature = "unstable-multicall")] | ||
let app = app.setting(AppSettings::Multicall); | ||
let matches = app.get_matches(); | ||
if matches.occurrences_of("install") > 0 { | ||
unimplemented!("Make hardlinks to the executable here"); | ||
} | ||
|
||
exit(match matches.subcommand_name() { | ||
Some("true") => 0, | ||
Some("false") => 1, | ||
_ => 127, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//! 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) | ||
.subcommand(App::new("hostname").about("shot hostname part of FQDN")) | ||
.subcommand(App::new("dnsdomainname").about("show domain name part of FQDN")); | ||
|
||
#[cfg(feature = "unstable-multicall")] | ||
let app = app.setting(AppSettings::Multicall); | ||
|
||
match app.get_matches().subcommand_name() { | ||
Some("hostname") => println!("www"), | ||
Some("dnsdomainname") => println!("example.com"), | ||
_ => exit(127), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.