Function gflags::parse

source ·
pub fn parse() -> Vec<&'static str>
Expand description

Initialize the value of all flags based on arguments from the command line at runtime.

This function must be called before accessing the values of any flags. After this function has been called, the values of flags are available in the .flag field of each flag.

The return vector contains everything on the command line which is not a flag. These are sometimes called positional arguments.


If we execute the following program with command line ./my_program a b c then nothing is printed because --print-args is not set. If we execute it with ./my_program --print-args a b c then the positional arguments a b c are printed.

gflags::define! {
    --print-args = false

fn main() {
    let args = gflags::parse();

    if PRINT_ARGS.flag {
        println!("args = {:?}", args);


Aborts the process with an error message if the command line does not conform to the flags defined by the application, or if any of the positional arguments are non-UTF8. Use gflags::parse_os if you need to support non-UTF8 positional arguments.