oscar.flag¶
-
oscar.flag.GLOBAL_FLAGS= <oscar.flag.GlobalFlagSet object>¶ GlobalFlagSet is a collection of namespaces and flag logic.
-
oscar.flag.REQUIRED= <oscar.flag._Required object>¶ Setting a flag’s
defaultto this constant marks it as required.
-
class
oscar.flag.Bool(description, default=None, secure=False)[source]¶ Boolean-valued flag.
-
type_str= 'Bool'¶
-
-
class
oscar.flag.Float(description, default=None, secure=False)[source]¶ Float-valued flag.
-
type_str= 'Float'¶
-
-
class
oscar.flag.GlobalFlagSet(usage=<function default_usage>, usage_long=<function default_usage_long>)[source]¶ GlobalFlagSet is a collection of namespaces and flag logic.
-
check_required()[source]¶ Returns a list of
(namespace, name, flag)of all unset, required flags.Return type: list[tuple(str, str, Var)]
-
find_short(flag)[source]¶ Find the namespace for a non-qualified
flag.If the
flagis not found or multiple flags are found,KeyErroris raised.Return type: str Raises: KeyError – if the flag is not found or ambiguous
-
get(namespace, flag)[source]¶ get the flag object associated with
flaginnamespace.Return type: Var Raises: KeyError – if the flag is not found
-
namespace(namespace)[source]¶ Returns a
NamespaceFlagSetassociated withnamespace.Return type: NamespaceFlagSet
-
parse_commandline(args)[source]¶ Parse a commandline into flags and arguments.
Parse a commandline. a single ‘-‘ and a double ‘–’ are treated as equivalent for denoting a flag. Flag values may be separated by ‘=’ or be the next argument. Booleans are a special case that indicate a true value or must have their values separated by ‘=’.
Raises: - KeyError – on unknown flag
- ParseException – on invalid command-line syntax
-
parse_environment(args)[source]¶ Parse environment variable tuples.
- Call with os.environ:
>>> import os >>> flag.parse_environment(os.environ.items())
Recognizes SECURED_SETTING_ prefixed flags, translates from base64 and maps to the short name. secure is also set to True on the underlying flag object, which should be respected by users of
visit()andvisit_all().
-
parse_ini(file_p)[source]¶ Parse a
ConfigParsercompatible file object.Namespaces are section headers, keys are flags:
[__main__] foo=bar [foo.bar] baz=42
file_ponly needs to implementreadline(size=0).
-
visit(func)[source]¶ Walk all set flags, calling
funcon each.Parameters: func (F(str, str, Var)) – visiting function
-
-
class
oscar.flag.Int(description, default=None, secure=False)[source]¶ Integer-valued flag.
-
type_str= 'Int'¶
-
-
class
oscar.flag.List(inner_type, separator, description, default=None, secure=False)[source]¶ Flag that is a list of another flag type.
-
type_str= 'List[_]'¶
-
-
class
oscar.flag.String(description, default=None, secure=False)[source]¶ String-valued flag.
-
type_str= 'String'¶
-
-
class
oscar.flag.Var(description, default=None, secure=False)[source]¶ Base of all flag accessors.
-
type_str= 'Unknown'¶
-
value= <object object>¶
-
-
oscar.flag.args()[source]¶ Return positional
argsfromGLOBAL_FLAGS.Return type: list[str]
-
oscar.flag.default_usage_long(globalflags, return_code=0)[source]¶ Default for printing out long-form usage.
-
oscar.flag.namespace(name)[source]¶ Return a namespace from
GLOBAL_FLAGS.Return type: NamespaceFlagSet
-
oscar.flag.parse_commandline(args)[source]¶ Parse commandline
argswithGLOBAL_FLAGS.
-
oscar.flag.parse_environment(args)[source]¶ Parse environment
argswithGLOBAL_FLAGS.
-
oscar.flag.parse_ini(file_p)[source]¶ Parse a
ConfigParsercompatible file withGLOBAL_FLAGS.