Skip to content
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

Add positional args for directory, branch, and repository. #20

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
6 changes: 6 additions & 0 deletions arg-parsing-test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,10 @@ write_conf_file() {
parse_args --message "a message"
assert that "$commit_message" = "a message"
}
@test ' correctly handles positional args.' {
parse_args pos-dir pos-branch pos-repo
assert that "$deploy_directory" = "pos-dir"
assert that "$deploy_branch" = "pos-branch"
assert that "$repo" = "pos-repo"
}

21 changes: 19 additions & 2 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -o errexit #abort if any command fails
me=$(basename "$0")

help_message="\
Usage: $me [-c FILE] [<options>]
Usage: $me [-c <FILE>] [<options>] [<directory> [<branch> [<repository>]]]
Deploy generated files to a git branch.

Options:
Expand All @@ -28,7 +28,14 @@ Variables:
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."
file specified by the '--config-file' option.

Positional Args:

At the end of the command, you can optionally specify the directory, branch,
and repository as well. Earlier values are required to specify later ones. For
example, in order to specify <branch>, you must also specify <directory>. Like
the command-line options, these"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this is unfinished.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matro so what was supposed to come after this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last minute coding before travel while tired didn't serve me here. b91b54e completes that sentence.


parse_args() {
# Set args from a local environment file.
Expand Down Expand Up @@ -61,6 +68,16 @@ parse_args() {
elif [[ $1 = "-n" || $1 = "--no-hash" ]]; then
GIT_DEPLOY_APPEND_HASH=false
shift
elif [[ -n ${1} ]]; then
# Set positional args
GIT_DEPLOY_DIR=$1
if [[ -n $2 ]]; then
GIT_DEPLOY_BRANCH=$2
fi
if [[ -n $3 ]]; then
GIT_DEPLOY_REPO=$3
fi
break
else
break
fi
Expand Down
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Do this every time you want to deploy, or have your CI server do it.
5. run `./deploy.sh`

### options

`deploy.sh [--config <FILE>] [<options>] [<directory> [<branch> [<repository>]]]`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the flag in the script is --config-file, but actually, how about we change it to just --config?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oy, good catch (and my bad). --config works for me.


`-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. __This option _must_ come first on the command-line__.
Expand All @@ -48,3 +51,5 @@ Do this every time you want to deploy, or have your CI server do it.
`-v`, `--verbose`: echo expanded commands as they are executed, using the xtrace option. This can be useful for debugging, as the output will include the values of variables that are being used, such as $commit_title and $deploy_directory. However, the script makes special effort to not output the value of $repo, as it may contain a secret authentication token.

`-e`, `--allow-empty`: allow deployment of an empty directory. By default, the script will abort if `deploy_directory` is empty.

`[<directory> [<branch> [<repository>]]]`: set the directory/branch/repository. __These options _must_ come at the end of the command-line__. Also, in order to specify later options, you _must_ specify each earlier one. So in order to specify "repository", you need to also specify "directory" and "branch".