Parsing command-line arguments

Environment variables are useful for using with containers. If you use your application from a console or you want to avoid a conflict of names with other variables, you can use command-line parameters. This is a more conventional way for developers to set parameters to the program.

You can also get command-line arguments with the env module. This contains the args function, which returns an Args object. This object is not an array or vector, but it's iterable and you can use the for loop processes all command-line arguments:

for arg in env::args() {
    // Interpret the arg here
}

This variant may come in handy in simple cases. For parsing arguments with complex rules, however, you have to use a command-line argument parser. A good implementation of this is contained in the clap crate.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.117.191