From 3bbb7b02d2c41fa4ff141d7e2a68d820136c3cd7 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Sun, 13 Oct 2019 10:14:05 +0200 Subject: [PATCH] [__sensible_editor] Allow to omit the --editor parameter if --state is absent --- cdist/conf/type/__sensible_editor/explorer/editor_path | 7 ++++++- cdist/conf/type/__sensible_editor/man.rst | 2 ++ cdist/conf/type/__sensible_editor/parameter/optional | 1 + cdist/conf/type/__sensible_editor/parameter/required | 1 - 4 files changed, 9 insertions(+), 2 deletions(-) delete mode 100644 cdist/conf/type/__sensible_editor/parameter/required diff --git a/cdist/conf/type/__sensible_editor/explorer/editor_path b/cdist/conf/type/__sensible_editor/explorer/editor_path index b6230545..d19a5b06 100644 --- a/cdist/conf/type/__sensible_editor/explorer/editor_path +++ b/cdist/conf/type/__sensible_editor/explorer/editor_path @@ -33,6 +33,9 @@ editor_no_alternative() { "$(test "${editors}" && echo "\nPlease choose one of:\n\n${editors}")" } +# No need to check for the path if the file is supposed to be removed. +test "$(cat "${__object}/parameter/state")" != 'absent' || exit 0 + case $("${__explorer}/os") in @@ -50,7 +53,9 @@ in ;; esac -editor=$(cat "${__object}/parameter/editor") +# Read --editor parameter and check its value since it is "optional" +editor=$(cat "${__object}/parameter/editor" 2>/dev/null) || true +test -n "${editor}" || die 'Please provide an --editor to configure.' case $editor in diff --git a/cdist/conf/type/__sensible_editor/man.rst b/cdist/conf/type/__sensible_editor/man.rst index 4260a369..b11aff46 100644 --- a/cdist/conf/type/__sensible_editor/man.rst +++ b/cdist/conf/type/__sensible_editor/man.rst @@ -18,6 +18,8 @@ editor Name or path of the editor to be selected. On systems other than Debian derivatives an absolute path is required. + It is permissible to omit this parameter if --state is absent. + OPTIONAL PARAMETERS ------------------- diff --git a/cdist/conf/type/__sensible_editor/parameter/optional b/cdist/conf/type/__sensible_editor/parameter/optional index ff72b5c7..ae55e240 100644 --- a/cdist/conf/type/__sensible_editor/parameter/optional +++ b/cdist/conf/type/__sensible_editor/parameter/optional @@ -1 +1,2 @@ +editor state diff --git a/cdist/conf/type/__sensible_editor/parameter/required b/cdist/conf/type/__sensible_editor/parameter/required deleted file mode 100644 index 85042acd..00000000 --- a/cdist/conf/type/__sensible_editor/parameter/required +++ /dev/null @@ -1 +0,0 @@ -editor