From cb3046ee53abd2b97fb5108f37824aa76e84a007 Mon Sep 17 00:00:00 2001 From: Alexander Hughes Date: Fri, 1 May 2020 08:31:46 -0400 Subject: [PATCH] Fail early on invalid save locations Currently the Render command expects either no save option or a file path. No save option defaults to stdout, a file path writes to the specified file. If a directory is specified no error is thrown until rendering is complete, by performing save location validation early Pegleg will now fail early. Change-Id: If75655e240c0ecbda00ea591e948e71010b4521d Signed-off-by: Alexander Hughes --- pegleg/cli/commands.py | 2 +- pegleg/cli/utils.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pegleg/cli/commands.py b/pegleg/cli/commands.py index c7fceab0..a460d783 100644 --- a/pegleg/cli/commands.py +++ b/pegleg/cli/commands.py @@ -177,7 +177,7 @@ def show(*, save_location, site_name): @site.command('render', help='Render a site through the deckhand engine.') -@utils.SAVE_LOCATION_OPTION +@utils.SAVE_FILE_OPTION @click.option( '-v', '--validate', diff --git a/pegleg/cli/utils.py b/pegleg/cli/utils.py index ee712e5e..e1af0cde 100644 --- a/pegleg/cli/utils.py +++ b/pegleg/cli/utils.py @@ -95,9 +95,20 @@ SAVE_LOCATION_OPTION = click.option( '-o', # DEPRECATED '--output', # DEPRECATED 'save_location', + type=click.Path(writable=True), help='Where to save the output. Defaults to stdout. ' '-o (--output) is deprecated and will be removed.') +SAVE_FILE_OPTION = click.option( + '-s', + '--save-location', + '-o', # DEPRECATED + '--output', # DEPRECATED + 'save_location', + type=click.Path(dir_okay=False, file_okay=True, writable=True), + help='File to save the output. Defaults to stdout. ' + '-o (--output) is deprecated and will be removed.') + REPOSITORY_CLONE_PATH_OPTION = click.option( '-p', '--clone-path',