mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
Migrate command line parsing to argparse (#50610)
* Start of migration to argparse * various fixes and improvements * Linting fixes * Test fixes * Fix vault_password_files * Add PrependAction for argparse * A bunch of additional tweak/fixes * Fix ansible-config tests * Fix man page generation * linting fix * More adhoc pattern fixes * Add changelog fragment * Add support for argcomplete * Enable argcomplete global completion * Rename PrependAction to PrependListAction to better describe what it does * Add documentation for installing and configuring argcomplete * Address rebase issues * Fix display encoding for vault * Fix line length * Address rebase issues * Handle rebase issues * Use mutually exclusive group instead of handling manually * Fix rebase issues * Address rebase issue * Update version added for argcomplete support * -e must be given a value * ci_complete
This commit is contained in:
@@ -14,28 +14,19 @@ from ansible.errors import AnsibleOptionsError
|
||||
def test_parse():
|
||||
""" Test adhoc parse"""
|
||||
adhoc_cli = AdHocCLI([])
|
||||
with pytest.raises(AnsibleOptionsError) as exec_info:
|
||||
with pytest.raises(SystemExit) as exec_info:
|
||||
adhoc_cli.parse()
|
||||
assert "Missing target hosts" == str(exec_info.value)
|
||||
|
||||
|
||||
def test_with_command():
|
||||
""" Test simple adhoc command"""
|
||||
module_name = 'command'
|
||||
adhoc_cli = AdHocCLI(args=['-m', module_name, '-vv'])
|
||||
adhoc_cli = AdHocCLI(args=['ansible', '-m', module_name, '-vv', 'localhost'])
|
||||
adhoc_cli.parse()
|
||||
assert context.CLIARGS['module_name'] == module_name
|
||||
assert display.verbosity == 2
|
||||
|
||||
|
||||
def test_with_extra_parameters():
|
||||
""" Test extra parameters"""
|
||||
adhoc_cli = AdHocCLI(args=['-m', 'command', 'extra_parameters'])
|
||||
with pytest.raises(AnsibleOptionsError) as exec_info:
|
||||
adhoc_cli.parse()
|
||||
assert "Extraneous options or arguments" == str(exec_info.value)
|
||||
|
||||
|
||||
def test_simple_command():
|
||||
""" Test valid command and its run"""
|
||||
adhoc_cli = AdHocCLI(['/bin/ansible', '-m', 'command', 'localhost', '-a', 'echo "hi"'])
|
||||
@@ -89,3 +80,10 @@ def test_run_import_playbook():
|
||||
adhoc_cli.run()
|
||||
assert context.CLIARGS['module_name'] == import_playbook
|
||||
assert "'%s' is not a valid action for ad-hoc commands" % import_playbook == str(exec_info.value)
|
||||
|
||||
|
||||
def test_run_no_extra_vars():
|
||||
adhoc_cli = AdHocCLI(args=['/bin/ansible', 'localhost', '-e'])
|
||||
with pytest.raises(SystemExit) as exec_info:
|
||||
adhoc_cli.parse()
|
||||
assert exec_info.value.code == 2
|
||||
|
||||
Reference in New Issue
Block a user