mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-04 16:21:28 -07:00
Save the command line arguments into a global context
* Once cli args are parsed, they're constant. So, save the parsed args into the global context for everyone else to use them from now on. * Port cli scripts to use the CLIARGS in the context * Refactor call to parse cli args into the run() method * Fix unittests for changes to the internals of CLI arg parsing * Port callback plugins to use context.CLIARGS * Got rid of the private self._options attribute * Use context.CLIARGS in the individual callback plugins instead. * Also output positional arguments in default and unixy plugins * Code has been simplified since we're now dealing with a dict rather than Optparse.Value
This commit is contained in:
parent
c18da65089
commit
afdbb0d9d5
36 changed files with 1033 additions and 868 deletions
30
test/units/test_context.py
Normal file
30
test/units/test_context.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# 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)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible import context
|
||||
|
||||
|
||||
class FakeOptions:
|
||||
pass
|
||||
|
||||
|
||||
def test_set_global_context():
|
||||
options = FakeOptions()
|
||||
options.tags = [u'production', u'webservers']
|
||||
options.check_mode = True
|
||||
options.start_at_task = u'Start with くらとみ'
|
||||
|
||||
expected = frozenset((('tags', (u'production', u'webservers')),
|
||||
('check_mode', True),
|
||||
('start_at_task', u'Start with くらとみ')))
|
||||
|
||||
context._init_global_context(options)
|
||||
assert frozenset(context.CLIARGS.items()) == expected
|
Loading…
Add table
Add a link
Reference in a new issue