tf.compat.v1.flags.FlagValues

Registry of 'Flag' objects.

A 'FlagValues' can then scan command line arguments, passing flag arguments through to the 'Flag' objects that it owns. It also provides easy access to the flag values. Typically only one 'FlagValues' object is needed by an application: flags.FLAGS

This class is heavily overloaded:

'Flag' objects are registered via setitem: FLAGS['longname'] = x # register a new flag

The .value attribute of the registered 'Flag' objects can be accessed as attributes of this 'FlagValues' object, through getattr. Both the long and short name of the original 'Flag' objects can be used to access its value: FLAGS.longname # parsed flag value FLAGS.x # parsed flag value (short name)

Command line arguments are scanned and passed to the registered 'Flag' objects through the call method. Unparsed arguments, including argv0 are returned. argv = FLAGS(sys.argv) # scan command line arguments

The original registered Flag objects can be retrieved through the use of the dictionary-like operator, getitem: x = FLAGS['longname'] # access the registered Flag object

The str() operator of a 'FlagValues' object provides help for all of the registered 'Flag' objects.

Methods

append_flag_values

Appends flags registered in another FlagValues instance.

Args
flag_values FlagValues, the FlagValues instance from which to copy flags.

append_flags_into_file

Appends all flags assignments from this FlagInfo object to a file.

Output will be in the format of a flagfile.

Args
filename str, name of the file.

find_module_defining_flag

Return the name of the module defining this flag, or default.

Args
flagname str, name of the flag to lookup.
default Value to return if flagname is not defined. Defaults to None.

Returns
The name of the module which registered the flag with this name. If no such module exists (i.e. no flag with this name exists), we return default.

find_module_id_defining_flag

Return the ID of the module defining this flag, or default.

Args
flagname str, name of the flag to lookup.
default Value to return if flagname is not defined. Defaults to None.

Returns
The ID of the module which registered the flag with this name. If no such module exists (i.e. no flag with this name exists), we return default.

flag_values_dict

Returns a dictionary that maps flag names to flag values.

flags_by_module_dict

Returns the dictionary of module_name -> list of defined flags.

Returns
A dictionary. Its keys are module names (strings). Its values are lists of Flag objects.

flags_by_module_id_dict

Returns the dictionary of module_id -> list of defined flags.

Returns
A dictionary. Its keys are module IDs (ints). Its values are lists of Flag objects.

flags_into_string

Returns a string with the flags assignments from this FlagValues object.

This function ignores flags whose value is None. Each flag assignment is separated by a newline.

Returns
str, the string with the flags assignments from this FlagValues object. The flags are ordered by (module_name, flag_name).

get_flag_value

Returns the value of a flag (if not None) or a default value.

Args
name str, the name of a flag.
default Default value to use if the flag value is None.

Returns
Requested flag value or default.

get_flags_for_module

Returns the list of flags defined by a module.

Args
module module|str, the module to get flags from.

Returns
[Flag], a new list of Flag instances. Caller may update this list as
desired none of those changes will affect the internals of this FlagValue instance.

get_help

Returns a help string for all known flags.

Args
prefix str, per-line output prefix.
include_special_flags bool, whether to include description of SPECIAL_FLAGS, i.e. --flagfile and --undefok.

Returns
str, formatted help message.

get_key_flags_for_module

Returns the list of key flags for a module.

Args
module module|str, the module to get key flags from.

Returns
[Flag], a new list of Flag instances. Caller may update this list as
desired none of those changes will affect the internals of this FlagValue instance.

is_gnu_getopt

is_parsed

Returns whether flags were parsed.

key_flags_by_module_dict

Returns the dictionary of module_name -> list of key flags.

Returns
A dictionary. Its keys are module names (strings). Its values are lists of Flag objects.

main_module_help

Describes the key flags of the main module.

Returns
str, describing the key flags of the main module.

mark_as_parsed

Explicitly marks flags as parsed.

Use this when the caller knows that this FlagValues has been parsed as if a call() invocation has happened. This is only a public method for use by things like appcommands which do additional command like parsing.

module_help

Describes the key flags of a module.