:right-sidebar: True OptionContext =================================================================== .. currentmodule:: gi.repository.GLib .. class:: OptionContext(*args, **kwargs) :no-contents-entry: A ``GOptionContext`` struct defines which options are accepted by the commandline option parser. The struct has only private fields and should not be directly accessed. Methods ------- .. rst-class:: interim-class .. class:: OptionContext :no-index: .. method:: add_group(group: ~gi._gi.OptionGroup) -> None Adds a :obj:`~gi.repository.GLib.OptionGroup` to the ``context``\, so that parsing with ``context`` will recognize the options in the group. Note that this will take ownership of the ``group`` and thus the ``group`` should not be freed. .. versionadded:: 2.6 :param group: the group to add .. method:: get_help_enabled() -> bool Returns whether automatic ``--help`` generation is turned on for ``context``\. See :func:`~gi.repository.GLib.OptionContext.set_help_enabled`. .. versionadded:: 2.6 .. method:: get_ignore_unknown_options() -> bool Returns whether unknown options are ignored or not. See :func:`~gi.repository.GLib.OptionContext.set_ignore_unknown_options`. .. versionadded:: 2.6 .. method:: get_main_group() -> ~gi._gi.OptionGroup Returns a pointer to the main group of ``context``\. .. versionadded:: 2.6 .. method:: parse(argv: ~typing.Sequence[str]) -> tuple[bool, list[str]] Parses the command line arguments, recognizing options which have been added to ``context``\. A side-effect of calling this function is that :func:`~gi.repository.GLib.set_prgname` will be called. If the parsing is successful, any parsed arguments are removed from the array and ``argc`` and ``argv`` are updated accordingly. A '--' option is stripped from ``argv`` unless there are unparsed options before and after it, or some of the options after it start with '-'. In case of an error, ``argc`` and ``argv`` are left unmodified. If automatic ``--help`` support is enabled (see :func:`~gi.repository.GLib.OptionContext.set_help_enabled`), and the ``argv`` array contains one of the recognized help options, this function will produce help output to stdout and call ``exit (0)``\. Note that function depends on the [current locale][setlocale] for automatic character set conversion of string and filename arguments. .. versionadded:: 2.6 :param argv: a pointer to the array of command line arguments .. method:: set_help_enabled(help_enabled: bool) -> None Enables or disables automatic generation of ``--help`` output. By default, :func:`~gi.repository.GLib.OptionContext.parse` recognizes ``--help``\, ``-h``\, ``-?``\, ``--help-all`` and ``--help-groupname`` and creates suitable output to stdout. .. versionadded:: 2.6 :param help_enabled: :const:`True` to enable ``--help``\, :const:`False` to disable it .. method:: set_ignore_unknown_options(ignore_unknown: bool) -> None Sets whether to ignore unknown options or not. If an argument is ignored, it is left in the ``argv`` array after parsing. By default, :func:`~gi.repository.GLib.OptionContext.parse` treats unknown options as error. This setting does not affect non-option arguments (i.e. arguments which don't start with a dash). But note that GOption cannot reliably determine whether a non-option belongs to a preceding unknown option. .. versionadded:: 2.6 :param ignore_unknown: :const:`True` to ignore unknown options, :const:`False` to produce an error when unknown options are met .. method:: set_main_group(group: ~gi._gi.OptionGroup) -> None Sets a :obj:`~gi.repository.GLib.OptionGroup` as main group of the ``context``\. This has the same effect as calling :func:`~gi.repository.GLib.OptionContext.add_group`, the only difference is that the options in the main group are treated differently when generating ``--help`` output. .. versionadded:: 2.6 :param group: the group to set as main group