From 6571f9dc0d7898c7705558f7ff5587965e99f1db Mon Sep 17 00:00:00 2001 From: Matt Pearson Date: Fri, 11 Dec 2015 12:46:49 -0800 Subject: [PATCH 1/2] Add '-h', '--help'. --- deploy.sh | 42 +++++++++++++++++++++++++++++++++++++++++- readme.md | 3 +++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/deploy.sh b/deploy.sh index d52a263..141476e 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,5 +1,42 @@ #!/usr/bin/env bash set -o errexit #abort if any command fails +me=$(basename "$0") + +read -r -d '' "help_message" <] + +Options: + + -h, --help Show this help information. + -v, --verbose Increase verbosity. Useful for debugging. + -e, --allow-empty Allow deployment of an empty directory. + -m, --message MESSAGE Specify the message used when committing on the + deploy branch. + -n, --no-hash Don't append the source commit's hash to the deploy + commit's message. + -c, --config-file PATH Override default & environment variables' values + with those in set in the file at 'PATH'. + +Variables: + + * GIT_DEPLOY_DIR Folder path containing the files to deploy. + * GIT_DEPLOY_BRANCH Commit deployable files to this branch. + * GIT_DEPLOY_REPO Push the deploy branch to this repository. + +These variables have default values defined in the script. The defaults can be +overridden by environment variables. Any environment variables are overridden +by values set in a '.env' file (if it exists), and in turn by those set in a +file specified by the '--config-file' option. +EOF + +print_help() { + printf "%s\n" "$help_message" +} main() { # Set args from a local environment file. @@ -12,7 +49,10 @@ main() { # Parse arg flags while : ; do - if [[ $1 = "-v" || $1 = "--verbose" ]]; then + if [[ $1 = "-h" || $1 = "--help" ]]; then + print_help + return 0 + elif [[ $1 = "-v" || $1 = "--verbose" ]]; then verbose=true shift elif [[ $1 = "-e" || $1 = "--allow-empty" ]]; then diff --git a/readme.md b/readme.md index 38e3d02..14ef3d9 100644 --- a/readme.md +++ b/readme.md @@ -17,6 +17,7 @@ You can also define any of variables using environment variables and configurati - `GIT_DEPLOY_DIR` - `GIT_DEPLOY_BRANCH` - `GIT_DEPLOY_REPO` +- `GIT_DEPLOY_APPEND_HASH` The script will set these variables in this order of preference: @@ -37,6 +38,8 @@ Do this every time you want to deploy, or have your CI server do it. 5. run `./deploy.sh` ### options +`-h`, `--help`: show the program's help info. + `-c`, `--config-file`: specify a file that overrides the script's default configuration, or those values set in `.env`. The syntax for this file should be normal `var=value` declarations. `-m`, `--message `: specify message to be used for the commit on `deploy_branch`. By default, the message is the title of the source commit, prepended with 'publish: '. From 338c5295adda14d93d161fd81ea21b2edfe8065d Mon Sep 17 00:00:00 2001 From: Matt Pearson Date: Fri, 11 Dec 2015 15:53:29 -0800 Subject: [PATCH 2/2] Remove `GIT_DEPLOY_APPEND_HASH` from the readme. This variable isn't working yet. Still using just `amend_hash` for now. --- readme.md | 1 - 1 file changed, 1 deletion(-) diff --git a/readme.md b/readme.md index 14ef3d9..7b449ed 100644 --- a/readme.md +++ b/readme.md @@ -17,7 +17,6 @@ You can also define any of variables using environment variables and configurati - `GIT_DEPLOY_DIR` - `GIT_DEPLOY_BRANCH` - `GIT_DEPLOY_REPO` -- `GIT_DEPLOY_APPEND_HASH` The script will set these variables in this order of preference: