make pager and editor configurable, specifically for ansible (#78816)

* make pager and editor configurable, specifically for ansilbe

  fallback on common ways to configure
pull/78910/head
Brian Coca 2 years ago committed by GitHub
parent c7cde2645d
commit 4b0697ee03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
minor_changes:
- allow user to set ansible specific env vars for selecting pager and editor, but still fall back to commonly used defaults.

@ -119,7 +119,7 @@ except ImportError:
class CLI(ABC):
''' code behind bin/ansible* programs '''
PAGER = 'less'
PAGER = C.config.get_config_value('PAGER')
# -F (quit-if-one-screen) -R (allow raw ansi control chars)
# -S (chop long lines) -X (disable termcap init and de-init)
@ -494,11 +494,11 @@ class CLI(ABC):
# this is a much simpler form of what is in pydoc.py
if not sys.stdout.isatty():
display.display(text, screen_only=True)
elif 'PAGER' in os.environ:
elif CLI.PAGER:
if sys.platform == 'win32':
display.display(text, screen_only=True)
else:
CLI.pager_pipe(text, os.environ['PAGER'])
CLI.pager_pipe(text)
else:
p = subprocess.Popen('less --version', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.communicate()
@ -508,12 +508,12 @@ class CLI(ABC):
display.display(text, screen_only=True)
@staticmethod
def pager_pipe(text, cmd):
def pager_pipe(text):
''' pipe text through a pager '''
if 'LESS' not in os.environ:
if 'less' in CLI.PAGER:
os.environ['LESS'] = CLI.LESS_OPTS
try:
cmd = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=sys.stdout)
cmd = subprocess.Popen(CLI.PAGER, shell=True, stdin=subprocess.PIPE, stdout=sys.stdout)
cmd.communicate(input=to_bytes(text))
except IOError:
pass

@ -183,7 +183,7 @@ class ConfigCLI(CLI):
# pylint: disable=unreachable
try:
editor = shlex.split(os.environ.get('EDITOR', 'vi'))
editor = shlex.split(C.config.get_config_value('EDITOR'))
editor.append(self.config_file)
subprocess.call(editor)
except Exception as e:

@ -1003,6 +1003,19 @@ DEFAULT_STDOUT_CALLBACK:
env: [{name: ANSIBLE_STDOUT_CALLBACK}]
ini:
- {key: stdout_callback, section: defaults}
EDITOR:
name: editor application touse
default: vi
descrioption:
- for the cases in which Ansible needs to return a file within an editor, this chooses the application to use
ini:
- section: defaults
key: editor
version_added: '2.15'
env:
- name: ANSIBLE_EDITOR
version_added: '2.15'
- name: EDITOR
ENABLE_TASK_DEBUGGER:
name: Whether to enable the task debugger
default: False
@ -1739,6 +1752,19 @@ OLD_PLUGIN_CACHE_CLEARING:
type: boolean
default: False
version_added: "2.8"
PAGER:
name: pager application to use
default: less
descrioption:
- for the cases in which Ansible needs to return output in pageable fasion, this chooses the application to use
ini:
- section: defaults
key: pager
version_added: '2.15'
env:
- name: ANSIBLE_PAGER
version_added: '2.15'
- name: PAGER
PARAMIKO_HOST_KEY_AUTO_ADD:
# TODO: move to plugin
default: False

@ -1123,7 +1123,7 @@ class VaultEditor:
os.chown(dest, prev.st_uid, prev.st_gid)
def _editor_shell_command(self, filename):
env_editor = os.environ.get('EDITOR', 'vi')
env_editor = C.config.get_config_value('EDITOR')
editor = shlex.split(env_editor)
editor.append(filename)

Loading…
Cancel
Save