mirror of
https://github.com/ansible/ansible.git
synced 2026-07-28 08:05:22 +02:00
cli: handle empty PAGER value (#86909)
Fixes: #86898 Signed-off-by: Abhijeet Kasurde <Akasurde@redhat.com>
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
---
|
||||
bugfixes:
|
||||
- cli - handle empty value for PAGER (https://github.com/ansible/ansible/issues/86898).
|
||||
@@ -514,17 +514,19 @@ class CLI(ABC):
|
||||
p = subprocess.Popen('less --version', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
p.communicate()
|
||||
if p.returncode == 0:
|
||||
CLI.pager_pipe(text, 'less')
|
||||
CLI.pager_pipe(text, pager='less')
|
||||
else:
|
||||
display.display(text, screen_only=True)
|
||||
|
||||
@staticmethod
|
||||
def pager_pipe(text):
|
||||
def pager_pipe(text, pager=None):
|
||||
""" pipe text through a pager """
|
||||
if 'less' in CLI.PAGER:
|
||||
pager_cmd = pager or CLI.PAGER
|
||||
|
||||
if 'less' in pager_cmd:
|
||||
os.environ['LESS'] = CLI.LESS_OPTS
|
||||
try:
|
||||
cmd = subprocess.Popen(CLI.PAGER, shell=True, stdin=subprocess.PIPE, stdout=sys.stdout)
|
||||
cmd = subprocess.Popen(pager_cmd, shell=True, stdin=subprocess.PIPE, stdout=sys.stdout)
|
||||
cmd.communicate(input=to_bytes(text))
|
||||
except (OSError, KeyboardInterrupt):
|
||||
pass
|
||||
|
||||
@@ -59,6 +59,16 @@ current_out="$(ansible-doc --playbook-dir ./ testns.testcol.yolo --type test | s
|
||||
expected_out="$(sed '1 s/\(^> TEST testns\.testcol\.yolo\).*(.*)$/\1/' yolo-text.output)"
|
||||
test "$current_out" == "$expected_out"
|
||||
|
||||
# PAGER is set to less by default, so we need to test with other pagers
|
||||
for pager in more cat; do
|
||||
echo "testing with pager $pager"
|
||||
PAGER=$pager ansible-doc --list testns.testcol --playbook-dir ./ 2>&1 | grep "${GREP_OPTS[@]}" -v "Invalid collection name"
|
||||
done
|
||||
|
||||
# set pager to empty string
|
||||
echo "testing with pager empty"
|
||||
PAGER="" ansible-doc --list testns.testcol --playbook-dir ./ 2>&1 | grep "${GREP_OPTS[@]}" -v "Invalid collection name"
|
||||
|
||||
# ensure we do work with valid collection name for list
|
||||
ansible-doc --list testns.testcol --playbook-dir ./ 2>&1 | grep -v "Invalid collection name"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user