1 From 5059daf8bd59a83f520c14731173ea76ce8b8661 Mon Sep 17 00:00:00 2001
2 From: Hartmut Goebel <h.goebel@crazy-compilers.com>
3 Date: Sun, 8 Sep 2019 13:09:15 +0200
4 Subject: [PATCH] [debops-defaults] If `view` is not available, try less, etc.
7 bin/debops-defaults | 21 +++++++++++++++------
8 1 file changed, 15 insertions(+), 6 deletions(-)
10 diff --git a/bin/debops-defaults b/bin/debops-defaults
11 index 9dd87fe0a..3e3db4c41 100755
12 --- a/bin/debops-defaults
13 +++ b/bin/debops-defaults
14 @@ -96,13 +96,22 @@ def main(role_list):
15 config = read_config(project_root)
16 playbooks_path = find_playbookpath(config, project_root, required=True)
18 - # Make sure required commands are present
19 - require_commands('view')
21 - if sys.stdout.isatty():
22 + # Check if one of the output commands is present
23 + sys.stdout = io.BytesIO() # suppress error message, if any
24 + for cmd_args in (('view', '+set ft=yaml', '-'),
28 + require_commands(cmd_args[0])
31 + # this command was not found
33 + sys.stdout = sys.__stdout__
35 + if cmd_args and sys.stdout.isatty():
36 # if script is run as standalone, redirect to view
37 - view = subprocess.Popen(['view', '+set ft=yaml', '-'],
38 - stdin=subprocess.PIPE)
39 + view = subprocess.Popen(cmd_args, stdin=subprocess.PIPE)
41 aggregate_defaults(playbooks_path, role_list, view.stdin)