Settings
ArgParse.ArgParseSettings — Type.ArgParseSettingsThe ArgParseSettings object contains all the settings to be used during argument parsing. Settings are divided in two groups: general settings and argument-table-related settings. While the argument table requires specialized functions such as @add_arg_table to be defined and manipulated, general settings are simply object fields (most of them are Bool or String) and can be passed to the constructor as keyword arguments, or directly set at any time.
This is the list of general settings currently available:
prog(default =""): the name of the program, as displayed in the auto-generated help and usage screens. If left empty, the source file name will be used.description(default =""): a description of what the program does, to be displayed in the auto-generated help-screen, between the usage lines and the arguments description. Ifpreformatted_descriptionisfalse(see below), it will be automatically formatted, but you can still force newlines by using two consecutive newlines in the string, and manually control spaces by using non-breakable spaces (the character'\ua0').preformatted_description(default =false): disable automatic formatting ofdescription.epilog(default =""): likedescription, but will be displayed at the end of the help-screen, after the arguments description. The same formatting rules also apply.preformatted_epilog(default =false): disable automatic formatting ofepilog.usage(default =""): the usage line(s) to be displayed in the help screen and when an error is found during parsing. If left empty, it will be auto-generated.version(default ="Unknown version"): version information. It's used by the:show_versionaction.add_help(default =true): iftrue, a--help, -hoption (triggering the:show_helpaction) is added to the argument table.add_version(default =false): iftrue, a--versionoption (triggering the:show_versionaction) is added to the argument table.fromfile_prefix_chars(default =Set{Char}()): an argument beginning with one of these characters will specify a file from which arguments will be read, one argument read per line. Alphanumeric characters and the hyphen-minus ('-') are prohibited.autofix_names(default =false): iftrue, will try to automatically fix the uses of dashes ('-') and underscores ('_') in option names and destinations: all underscores will be converted to dashes in long option names; also, associated destination names, if auto-generated (see the Argument names section), will have dashes replaced with underscores, both for long options and for positional arguments. For example, an option declared as"--my-opt"will be associated with the key"my_opt"by default. It is especially advisable to turn this option on then parsing with theas_symbols=trueargument toparse_args.error_on_conflict(default =true): iftrue, throw an error in case conflicting entries are added to the argument table; iffalse, later entries will silently take precedence. See the Conflicts and overrides srction for a detailed description of what conflicts are and what is the exact behavior when this setting isfalse.suppress_warnings(default =false): istrue, all warnings will be suppressed.allow_ambiguous_opts(default =false): iftrue, ambiguous options such as-1will be accepted.commands_are_required(default =true): iftrue, commands will be mandatory. See the Commands section.exc_handler(default =ArgParse.default_handler): this is a function which is invoked when an error is detected during parsing (e.g. an option is not recognized, a required argument is not passed etc.). It takes two arguments: thesettings::ArgParseSettingsobject and theerr::ArgParseErrorexception. The default handler prints the error text and the usage screen on standard error and exits with error code 1:function default_handler(settings::ArgParseSettings, err, err_code::Int = 1) println(stderr, err.text) println(stderr, usage_string(settings)) exit(err_code) endThe module also provides a function
ArgParse.debug_handler(not exported) which will just rethrow the error.exit_after_help(default =true): exits Julia (with error code0) when the:show_helpor:show_versionactions are triggered. Iffalse, those actions will just stop the parsing and makeparse_argsreturnnothing.
Here is a usage example:
settings = ArgParseSettings(description = "This program does something",
commands_are_required = false,
version = "1.0",
add_version = true)which is also equivalent to:
settings = ArgParseSettings()
settings.description = "This program does something."
settings.commands_are_required = false
settings.version = "1.0"
settings.add_version = trueAs a shorthand, the description field can be passed without keyword, which makes this equivalent to the above:
settings = ArgParseSettings("This program does something",
commands_are_required = false,
version = "1.0",
add_version = true)Most settings won't take effect until parse_args is invoked, but a few will have immediate effects: autofix_names, error_on_conflict, suppress_warnings, allow_ambiguous_opts.