Skip to content

Commit

Permalink
examples: fix indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sru committed Aug 27, 2015
1 parent 4b8908b commit d4f1b74
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 190 deletions.
38 changes: 19 additions & 19 deletions examples/04_UsingMatches.rs
Expand Up @@ -4,19 +4,19 @@ use clap::{App, Arg};

fn main() {

// Once all App settings (including all arguments) have been set, you call get_matches() which
// parses the string provided by the user, and returns all the valid matches to the ones you
// specified.
//
// You can then query the matches struct to get information about how the user ran the program
// at startup.
//
// For this example, let's assume you created an App which accepts three arguments (plus two
// generated by clap), a flag to display debugging information triggered with "-d" or
// "--debug" as well as an option argument which specifies a custom configuration file to use
// triggered with "-c file" or "--config file" or "--config=file" and finally a positional
// argument which is the input file we want to work with, this will be the only required
// argument.
// Once all App settings (including all arguments) have been set, you call get_matches() which
// parses the string provided by the user, and returns all the valid matches to the ones you
// specified.
//
// You can then query the matches struct to get information about how the user ran the program
// at startup.
//
// For this example, let's assume you created an App which accepts three arguments (plus two
// generated by clap), a flag to display debugging information triggered with "-d" or
// "--debug" as well as an option argument which specifies a custom configuration file to use
// triggered with "-c file" or "--config file" or "--config=file" and finally a positional
// argument which is the input file we want to work with, this will be the only required
// argument.
let matches = App::new("MyApp")
.about("Parses an input file to do awesome things")
.version("1.0")
Expand All @@ -37,18 +37,18 @@ fn main() {

// We can find out whether or not debugging was turned on
if matches.is_present("debug") {
println!("Debugging is turned on");
println!("Debugging is turned on");
}

// If we wanted to some custom initialization based off some configuration file provided
// by the user, we could get the file (A string of the file)
if let Some(ref file) = matches.value_of("config") {
println!("Using config file: {}", file);
println!("Using config file: {}", file);
}

// Because "input" is required we can safely call unwrap() because had the user NOT
// Because "input" is required we can safely call unwrap() because had the user NOT
// specified a value, clap would have explained the error the user, and exited.
println!("Doing real work with file: {}", matches.value_of("input").unwrap() );

// Continued program logic goes here...
}
}
52 changes: 26 additions & 26 deletions examples/05_FlagArgs.rs
Expand Up @@ -4,43 +4,43 @@ use clap::{App, Arg};

fn main() {

// Of the three argument types, flags are the most simple. Flags are simple switches which can
// be either "on" or "off"
//
// clap also supports multiple occurrences of flags, the common example is "verbosity" where a
// user could want a little information with "-v" or tons of information with "-v -v" or "-vv"
// Of the three argument types, flags are the most simple. Flags are simple switches which can
// be either "on" or "off"
//
// clap also supports multiple occurrences of flags, the common example is "verbosity" where a
// user could want a little information with "-v" or tons of information with "-v -v" or "-vv"
let matches = App::new("MyApp")
// Regular App configuration goes here...
// Regular App configuration goes here...

// We'll add a flag that represents an awesome meter...
//
// I'll explain each possible setting that "flags" accept. Keep in mind
// that you DO NOT need to set each of these for every flag, only the ones
// you want for your individual case.
// We'll add a flag that represents an awesome meter...
//
// I'll explain each possible setting that "flags" accept. Keep in mind
// that you DO NOT need to set each of these for every flag, only the ones
// you want for your individual case.
.arg(Arg::with_name("awesome")
.help("turns up the awesome") // Displayed when showing help info
.short("a") // Trigger this arg with "-a"
.long("awesome") // Trigger this arg with "--awesome"
.multiple(true) // This flag should allow multiple
// occurrences such as "-aaa" or "-a -a"
.requires("config") // Says, "If the user uses -a, they MUST
// also use this other 'config' arg too"
// Can also specifiy a list using
// requires_all(Vec<&str>)
.short("a") // Trigger this arg with "-a"
.long("awesome") // Trigger this arg with "--awesome"
.multiple(true) // This flag should allow multiple
// occurrences such as "-aaa" or "-a -a"
.requires("config") // Says, "If the user uses -a, they MUST
// also use this other 'config' arg too"
// Can also specifiy a list using
// requires_all(Vec<&str>)
.conflicts_with("output") // Opposite of requires(), says "if the
// user uses -a, they CANNOT use 'output'"
// also has a mutually_excludes_all(Vec<&str>)
// user uses -a, they CANNOT use 'output'"
// also has a mutually_excludes_all(Vec<&str>)
)
// NOTE: In order to compile this example, comment out requres() and
// mutually_excludes() because we have not defined an "output" or "config"
// argument.
// NOTE: In order to compile this example, comment out requres() and
// mutually_excludes() because we have not defined an "output" or "config"
// argument.
.get_matches();

// We can find out whether or not awesome was used
if matches.is_present("awesome") {
println!("Awesomeness is turned on");
println!("Awesomeness is turned on");
}

// If we set the mutliple() option of a flag we can check how many times the user specified
//
// Note: if we did not specify the multiple() option, and the user used "awesome" we would get
Expand Down
68 changes: 34 additions & 34 deletions examples/06_PositionalArgs.rs
Expand Up @@ -4,53 +4,53 @@ use clap::{App, Arg};

fn main() {

// Positional arguments are those values after the program name which are not preceded by any
// identifier (such as "myapp some_file"). Positionals support many of the same options as
// flags, as well as a few additional ones.
// Positional arguments are those values after the program name which are not preceded by any
// identifier (such as "myapp some_file"). Positionals support many of the same options as
// flags, as well as a few additional ones.
let matches = App::new("MyApp")
// Regular App configuration goes here...
// Regular App configuration goes here...

// We'll add two positional arguments, a input file, and a config file.
//
// I'll explain each possible setting that "positionals" accept. Keep in
// mind that you DO NOT need to set each of these for every flag, only the
// ones that apply to your individual case.
// We'll add two positional arguments, a input file, and a config file.
//
// I'll explain each possible setting that "positionals" accept. Keep in
// mind that you DO NOT need to set each of these for every flag, only the
// ones that apply to your individual case.
.arg(Arg::with_name("input")
.help("the input file to use") // Displayed when showing help info
.index(1) // Set the order in which the user must
// specify this argument (Starts at 1)
.requires("config") // Says, "If the user uses "input", they MUST
// also use this other 'config' arg too"
// Can also specifiy a list using
// requires_all(Vec<&str>)
.index(1) // Set the order in which the user must
// specify this argument (Starts at 1)
.requires("config") // Says, "If the user uses "input", they MUST
// also use this other 'config' arg too"
// Can also specifiy a list using
// requires_all(Vec<&str>)
.conflicts_with("output") // Opposite of requires(), says "if the
// user uses -a, they CANNOT use 'output'"
// also has a mutually_excludes_all(Vec<&str>)
.required(true) // By default this argument MUST be present
// NOTE: mutual exclusions take precedence over
// required arguments
// user uses -a, they CANNOT use 'output'"
// also has a mutually_excludes_all(Vec<&str>)
.required(true) // By default this argument MUST be present
// NOTE: mutual exclusions take precedence over
// required arguments
)
.arg(Arg::with_name("config")
.help("the config file to use")
.index(2)) // Note, we do not need to specify required(true)
// if we don't want to, because "input" already
// requires "config"
// Note, we also do not need to specify requires("input")
// because requires lists are automatically two-way
.arg(Arg::with_name("config")
.help("the config file to use")
.index(2)) // Note, we do not need to specify required(true)
// if we don't want to, because "input" already
// requires "config"
// Note, we also do not need to specify requires("input")
// because requires lists are automatically two-way

// NOTE: In order to compile this example, comment out mutually_excludes()
// because we have not defined an "output" argument.
// NOTE: In order to compile this example, comment out mutually_excludes()
// because we have not defined an "output" argument.
.get_matches();

// We can find out whether or not "input" or "config" were used
// We can find out whether or not "input" or "config" were used
if matches.is_present("input") {
println!("An input file was specified");
println!("An input file was specified");
}

// We can also get the values for those arguments
if let Some(ref in_file) = matches.value_of("input") {
// It's safe to call unwrap() because of the required options we set above
println!("Doing work with {} and {}", in_file, matches.value_of("config").unwrap());
// It's safe to call unwrap() because of the required options we set above
println!("Doing work with {} and {}", in_file, matches.value_of("config").unwrap());
}
// Continued program logic goes here...
}
70 changes: 35 additions & 35 deletions examples/07_OptionArgs.rs
Expand Up @@ -4,60 +4,60 @@ use clap::{App, Arg};

fn main() {

// Option arguments are those that take an additional value, such as "-c value". In clap they
// support three types of specification, those with short() as "-o some", or those with long()
// as "--option value" or "--option=value"
//
// Options also support a multiple setting, which is discussed in the example below.
// Option arguments are those that take an additional value, such as "-c value". In clap they
// support three types of specification, those with short() as "-o some", or those with long()
// as "--option value" or "--option=value"
//
// Options also support a multiple setting, which is discussed in the example below.
let matches = App::new("MyApp")
// Regular App configuration goes here...
// Regular App configuration goes here...

// Assume we an application that accepts an input file via the "-i file"
// or the "--input file" (as wel as "--input=file").
// Below every setting supported by option arguments is discussed.
// NOTE: You DO NOT need to specify each setting, only those which apply
// to your particular case.
// Assume we an application that accepts an input file via the "-i file"
// or the "--input file" (as wel as "--input=file").
// Below every setting supported by option arguments is discussed.
// NOTE: You DO NOT need to specify each setting, only those which apply
// to your particular case.
.arg(Arg::with_name("input")
.help("the input file to use") // Displayed when showing help info
.takes_value(true) // MUST be set to true in order to be an "option" argument
.short("i") // This argument is triggered with "-i"
.long("input") // This argument is triggered with "--input"
.multiple(true) // Set to true if you wish to allow multiple occurrences
// such as "-i file -i other_file -i third_file"
.required(true) // By default this argument MUST be present
// NOTE: mutual exclusions take precedence over
// required arguments
.requires("config") // Says, "If the user uses "input", they MUST
// also use this other 'config' arg too"
// Can also specifiy a list using
// requires_all(Vec<&str>)
.takes_value(true) // MUST be set to true in order to be an "option" argument
.short("i") // This argument is triggered with "-i"
.long("input") // This argument is triggered with "--input"
.multiple(true) // Set to true if you wish to allow multiple occurrences
// such as "-i file -i other_file -i third_file"
.required(true) // By default this argument MUST be present
// NOTE: mutual exclusions take precedence over
// required arguments
.requires("config") // Says, "If the user uses "input", they MUST
// also use this other 'config' arg too"
// Can also specifiy a list using
// requires_all(Vec<&str>)
.conflicts_with("output") // Opposite of requires(), says "if the
// user uses -a, they CANNOT use 'output'"
// also has a conflicts_with_all(Vec<&str>)
// user uses -a, they CANNOT use 'output'"
// also has a conflicts_with_all(Vec<&str>)
)
// NOTE: In order to compile this example, comment out conflicts_with()
// and requires() because we have not defined an "output" or "config"
// argument.
// NOTE: In order to compile this example, comment out conflicts_with()
// and requires() because we have not defined an "output" or "config"
// argument.
.get_matches();

// We can find out whether or not "input" was used
// We can find out whether or not "input" was used
if matches.is_present("input") {
println!("An input file was specified");
println!("An input file was specified");
}

// We can also get the value for "input"
//
// NOTE: If we specified multiple(), this will only return the _FIRST_
// occurrence
if let Some(ref in_file) = matches.value_of("input") {
println!("An input file: {}", in_file);
println!("An input file: {}", in_file);
}

// If we specified the multiple() setting we can get all the values
if let Some(ref in_v) = matches.values_of("input") {
for in_file in in_v.iter() {
println!("An input file: {}", in_file);
}
for in_file in in_v.iter() {
println!("An input file: {}", in_file);
}
}

// We can see how many times the option was used with the occurrences_of() method
Expand Down

0 comments on commit d4f1b74

Please sign in to comment.