gfw.common.cli.Option#

class Option(*flags, type, default=None, required=False, **kwargs)[source]#

Represents a CLI option.

Provides a declarative interface to define command-line options that can be added to an argparse.ArgumentParser instance via its add_argument() method.

Parameters:
  • *flags (str) –

    One or more command-line flag strings for this option. These are passed directly to argparse’s add_argument(). The first long flag (if any) is used to derive the internal name, which is also used as the destination (dest()) when parsing.

    Three examples:
    Option("-c", "--config-file", ...)  # Short and long form
    Option("--verbose", ...)  # Long form only
    Option("-v", ...)  # Short form only
    

  • type (Callable[[...], Any]) – A callable that converts the command-line string to the desired Python type. Typically, a built-in type like str, int, float, or bool.

  • default (Any) – The default value to use if the option is not provided. This should match the specified type, although no enforcement is currently done.

  • required (bool) – We capture the required flag so we can validate it not only against command-line parameters but also against the provided config file.

  • **kwargs (Any) – Additional keyword arguments passed directly to add_argument().

Methods

Attributes

dest

Returns the internal variable name used by argparse for this option.

property dest: str#

Returns the internal variable name used by argparse for this option.

Uses the last long flag (e.g., --config-file) if present, or the first flag as a fallback. Dashes are converted to underscores for compatibility with argparse’s variable naming.