mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 20:01:25 -07:00
The goal of breaking apart the base_parser() function is to get rid of a bunch of conditionals and parameters in the code and, instead, make code look like simple composition. When splitting, a choice had to be made as to whether this would operate by side effect (modifying a passed in parser) or side effect-free (returning a new parser everytime). Making a version that's side-effect-free appears to be fighting with the optparse API (it wants to work by creating a parser object, configuring the object, and then parsing the arguments with it) so instead, make it clear that our helper functions are modifying the passed in parser by (1) not returning the parser and (2) changing the function names to be more clear that it is operating by side-effect. Also move all of the generic optparse code, along with the argument context classes, into a new subdirectory.
29 lines
1 KiB
Python
29 lines
1 KiB
Python
# Copyright: (c) 2018, Toshio Kuratomi <tkuratomi@ansible.com>
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# Make coding more python3-ish
|
|
from __future__ import (absolute_import, division, print_function)
|
|
__metaclass__ = type
|
|
|
|
"""
|
|
Context of the running Ansible.
|
|
|
|
In the future we *may* create Context objects to allow running multiple Ansible plays in parallel
|
|
with different contexts but that is currently out of scope as the Ansible library is just for
|
|
running the ansible command line tools.
|
|
|
|
These APIs are still in flux so do not use them unless you are willing to update them with every Ansible release
|
|
"""
|
|
|
|
from ansible.arguments.context_objects import CLIArgs, GlobalCLIArgs
|
|
|
|
|
|
# Note: this is not the singleton version. The Singleton is only created once the program has
|
|
# actually parsed the args
|
|
CLIARGS = CLIArgs({})
|
|
|
|
|
|
def _init_global_context(cli_args):
|
|
"""Initialize the global context objects"""
|
|
global CLIARGS
|
|
CLIARGS = GlobalCLIArgs.from_options(cli_args)
|