Add fallback value for editor_cmd
Fixes
@@ -25,6 +25,7 @@ import yaml
from click import ClickException
from contextlib import contextmanager
+from distutils.spawn import find_executable
from patroni.config import Config
from patroni.dcs import get_dcs as _get_dcs
from patroni.exceptions import PatroniException
@@ -1088,9 +1089,16 @@ def invoke_editor(before_editing, cluster_name):
:param before_editing: human representation before editing
:returns tuple of human readable and parsed datastructure after changes
"""
+ if 'EDITOR' in os.environ:
editor_cmd = os.environ.get('EDITOR')
+ else:
+ for editor in ('editor', 'vi'):
+ editor_cmd = find_executable(editor)
+ if editor_cmd:
+ logging.debug('Setting fallback editor_cmd=%s', editor)
+ break
if not editor_cmd:
- raise PatroniCtlException('EDITOR environment variable is not set')
+ raise PatroniCtlException('EDITOR environment variable is not set. editor or vi are not available')
with temporary_file(contents=before_editing.encode('utf-8'),
suffix='.yaml',
