flexget.options module#

exception flexget.options.ParserError(message, parser)[source]#

Bases: Exception

class flexget.options.ArgumentParser(**kwargs)[source]#

Bases: ArgumentParser

Mimics the default argparse.ArgumentParser class.

There are a few distinctions, mostly to ease subparser usage:

  • If add_subparsers is called with the nested_namespaces kwarg, all subcommand options will be stored in a nested namespace based on the command name for the subparser

  • Adds the add_subparser method. After add_subparsers has been called, the add_subparser method can be used instead of the add_parser method of the object returned by the add_subparsers call.

  • add_subparser takes takes the parent_defaults argument, which will set/change the defaults for the parent parser when that subparser is selected.

  • The get_subparser method will get the ArgumentParser instance for an existing subparser on this parser

  • For any arguments defined both in this parser and one of its subparsers, the selected subparser default will override the main one.

  • Adds the set_post_defaults method. This works like the normal argparse set_defaults method, but all actions and subparsers will be run before any of these defaults are set.

  • Command shortening: If the command for a subparser is abbreviated unambiguously, it will still be accepted.

  • The add_argument nargs keyword argument supports a range of arguments, e.g. 2-4

  • If the raise_errors keyword argument to parse_args is True, a ParserError will be raised instead of sys.exit

  • If the file argument is given to parse_args, output will be printed there instead of sys.stdout or stderr

_get_values(action, arg_strings)[source]#

Complete the full name for partial subcommands.

_print_message(message, file=None)[source]#

If a file argument was passed to parse_args make sure output goes there.

add_argument(dest, ..., name=value, ...)[source]#
add_argument(option_string, option_string, ..., name=value, ...)
add_subparser(name, **kwargs)[source]#

Add a parser for a new subcommand and return it.

Parameters:
  • name (str) – Name of the subcommand

  • parent_defaults – Default argument values which should be supplied to the parent parser if this subparser is selected.

add_subparsers(**kwargs)[source]#

Add a parser for a new subcommand and return it.

Parameters:

nested_namespaces – If True, options from subparsers will appear in nested namespace under the subparser name.

error(message: string)[source]#

Prints a usage message incorporating the message to stderr and exits.

If you override this in a subclass, it should not return – it should either exit or raise an exception.

Parameters:

msg (str)

get_subparser(name, default=<object object>)[source]#
Parameters:

name (str)

parse_args(args=None, namespace=None, raise_errors=False, file=None)[source]#
Parameters:
  • raise_errors (bool) – If this is true, errors will be raised as ParserError instead of calling sys.exit

  • args (list[str] | None)

  • namespace (Namespace | None)

  • file (TextIO | None)

parse_known_args(args=None, namespace=None, do_help=None)[source]#
Parameters:
set_post_defaults(**kwargs)[source]#

Like set_defaults method, but these defaults will be defined after parsing instead of before.

do_help = True#
file: IO[str] | None = None#
class flexget.options.CoreArgumentParser(**kwargs)[source]#

Bases: ArgumentParser

The core argument parser, contains the manager arguments, command parsers, and plugin arguments.

Warning: Only gets plugin arguments if instantiated after plugins have been loaded.

add_subparsers(**kwargs)[source]#

Add a parser for a new subcommand and return it.

Parameters:

nested_namespaces – If True, options from subparsers will appear in nested namespace under the subparser name.

parse_args(*args, **kwargs)[source]#
Parameters:

raise_errors – If this is true, errors will be raised as ParserError instead of calling sys.exit

class flexget.options.CronAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None, deprecated=False)[source]#

Bases: Action

class flexget.options.DebugAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None, deprecated=False)[source]#

Bases: Action

class flexget.options.DebugTraceAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None, deprecated=False)[source]#

Bases: Action

class flexget.options.HelpAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None, deprecated=False)[source]#

Bases: Action

Override the default help command so that we can conditionally disable it to prevent program exit.

class flexget.options.InjectAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None, deprecated=False)[source]#

Bases: Action

class flexget.options.NestedSubparserAction(*args, **kwargs)[source]#

Bases: _SubParsersAction

add_parser(name, parent_defaults=None, **kwargs)[source]#
Parameters:
  • name (str)

  • parent_defaults (dict | None)

class flexget.options.ParseExtrasAction(option_strings, parser, help=None, metavar=None, dest=None, required=False)[source]#

Bases: Action

Extra arguments are taken, and then parsed with a different parser.

class flexget.options.ScopedNamespace(**kwargs)[source]#

Bases: Namespace

class flexget.options.VersionAction(option_strings, version=None, dest='==SUPPRESS==', default='==SUPPRESS==', help=None, deprecated=False)[source]#

Bases: _VersionAction

Action to print the current version. Also checks latest release revision.

flexget.options.get_parser(command=None)[source]#
Parameters:

command (str | None)

Return type:

ArgumentParser

flexget.options.register_command(command, callback, **kwargs)[source]#

Register a callback function to be executed when flexget is launched with the given command.

Parameters:
  • command (str) – The command being defined.

  • callback (Callable[[flexget.manager.Manager, Namespace], Any]) – Callback function executed when this command is invoked from the CLI. Should take manager instance and parsed argparse namespace as parameters.

  • kwargs – Other keyword arguments will be passed to the arparse.ArgumentParser constructor

Returns:

An argparse.ArgumentParser instance ready to be configured with the options for this command.

Return type:

ArgumentParser

flexget.options.required_length(nmin, nmax)[source]#

Generate a custom Action to validate an arbitrary range of arguments.

Parameters: