Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve cli argument handling (#2099)
* Include opt-in rules when listing tags and rules With PR #1450 optional rules with the 'opt-in' tag were introduced and according to the docs, listing rules and tags should also list the opt-in rules. Fixes: #2068 Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at> * gracefully handle invalid format options with listing rules Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at> * put arguments -L and -T into a mutually exclusive group We either print a list of rules or a list of tags, but never both at the same time. So it makes no sense to allow giving both arguments at the same time. Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at> * always provide a long form of cli arguments Having short cli arguments for often used options is nice to have when using the command in an interactive shell. For writing scripts it would be better to have long forms of arguments as it increases the readebility. Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at> * Update tox.yml Co-authored-by: Sorin Sbarnea <sorin.sbarnea@gmail.com>
- Loading branch information
1 parent
cd32348
commit f9ad8ea
Showing
6 changed files
with
119 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
"""Tests related to our logging/verbosity setup.""" | ||
|
||
import os | ||
|
||
import pytest | ||
|
||
from ansiblelint.testing import run_ansible_lint | ||
|
||
|
||
def test_list_rules_includes_opt_in_rules() -> None: | ||
"""Checks that listing rules also includes the opt-in rules.""" | ||
# Piggyback off the .yamllint in the root of the repo, just for testing. | ||
# We'll "override" it with the one in the fixture. | ||
cwd = os.path.realpath( | ||
os.path.join(os.path.dirname(os.path.realpath(__file__)), "..") | ||
) | ||
fakerole = os.path.join("test", "fixtures", "list-rules-tests") | ||
|
||
result_list_rules = run_ansible_lint("-L", fakerole, cwd=cwd) | ||
|
||
assert ("opt-in" in result_list_rules.stdout) is True | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("result", "returncode", "format_string"), | ||
( | ||
(False, 0, "plain"), | ||
(False, 0, "rich"), | ||
(False, 0, "rst"), | ||
(True, 2, "json"), | ||
(True, 2, "codeclimate"), | ||
(True, 2, "quiet"), | ||
(True, 2, "pep8"), | ||
(True, 2, "foo"), | ||
), | ||
ids=( | ||
"plain", | ||
"rich", | ||
"rst", | ||
"json", | ||
"codeclimate", | ||
"quiet", | ||
"pep8", | ||
"foo", | ||
), | ||
) | ||
def test_list_rules_with_format_option( | ||
result: bool, returncode: int, format_string: str | ||
) -> None: | ||
"""Checks that listing rules with format options works.""" | ||
# Piggyback off the .yamllint in the root of the repo, just for testing. | ||
# We'll "override" it with the one in the fixture. | ||
cwd = os.path.realpath( | ||
os.path.join(os.path.dirname(os.path.realpath(__file__)), "..") | ||
) | ||
fakerole = os.path.join("test", "fixtures", "list-rules-tests") | ||
|
||
result_list_rules = run_ansible_lint("-f", format_string, "-L", fakerole, cwd=cwd) | ||
print(result_list_rules.stdout) | ||
|
||
assert (f"invalid choice: '{format_string}'" in result_list_rules.stderr) is result | ||
assert ("syntax-check" in result_list_rules.stdout) is not result | ||
assert result_list_rules.returncode is returncode | ||
|
||
|
||
def test_list_tags_includes_opt_in_rules() -> None: | ||
"""Checks that listing tags also includes the opt-in rules.""" | ||
# Piggyback off the .yamllint in the root of the repo, just for testing. | ||
# We'll "override" it with the one in the fixture. | ||
cwd = os.path.realpath( | ||
os.path.join(os.path.dirname(os.path.realpath(__file__)), "..") | ||
) | ||
fakerole = os.path.join("test", "fixtures", "list-rules-tests") | ||
|
||
result_list_tags = run_ansible_lint("-L", fakerole, cwd=cwd) | ||
|
||
assert ("opt-in" in result_list_tags.stdout) is True |