-
-
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.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
extern crate clap; | ||
|
||
use clap::{App, AppSettings, SubCommand}; | ||
|
||
fn main() { | ||
// You can use AppSettings to change the application level behavior of clap. .setting() function | ||
// of App struct takes AppSettings enum as argument. There is also .settings() function which | ||
// takes slice of AppSettings enum. You can learn more about AppSettings in the documentation, | ||
// which also has examples on each setting. | ||
// | ||
// This example will only show usage of one AppSettings setting. See documentation for more | ||
// information. | ||
|
||
let matches = App::new("myapp") | ||
.setting(AppSettings::SubcommandsNegateReqs) | ||
// Negates requirement of parent command. | ||
|
||
.arg_from_usage("<input> 'input file to use'") | ||
// Required positional argument called input. This | ||
// will be only required if subcommand is not present. | ||
|
||
.subcommand(SubCommand::with_name("help") | ||
.about("shows help message")) | ||
// if program is invoked with subcommand, you do not | ||
// need to specify the <input> argument anymore due to | ||
// the AppSettings::SubcommandsNegateReqs setting. | ||
|
||
.get_matches(); | ||
|
||
// Contiued program logic goes here... | ||
} |