Skip to content

Add '-h', '--help' message. #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
#!/usr/bin/env bash
set -o errexit #abort if any command fails
me=$(basename "$0")

read -r -d '' "help_message" <<EOF || true

Deploy generated files to a git branch.

Usage:

$me [<options>]

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.
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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 <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: '.
Expand Down