Give all subcommands an optional setup() function that will be called by git-flow in order to let the subcommand initialize its environment.
Give all the branch-type subcommands a default explicit "list" action, too.
Order the functions inside each of the subcommands in a specific order, for consistency:
- usage()
- setup()
- cmd_default()
- cmd_list()
- cmd_help()
- parse_args()
- other commands
diff --git a/git-flow-release b/git-flow-release
index 1fec600..b5f5959 100644
--- a/git-flow-release
+++ b/git-flow-release
@@ -13,7 +13,7 @@
#
usage() {
- echo "usage: git flow release"
+ echo "usage: git flow release [list]"
echo " git flow release start <version>"
echo " git flow release finish <version>"
# TODO
@@ -29,21 +29,17 @@
#echo "--push Push to the origin repo when finished"
}
-parse_args() {
- VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
- VERSION="$1"
- if [ "$VERSION" = "" ]; then
- echo "Missing argument <version>."
- usage
- exit 1
- fi
+# setup will always be called before the actual cmd_* functions
+setup() {
PREFIX=$(git config --get gitflow.prefix.release || echo release/)
- BRANCH=$PREFIX$VERSION
+ VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
}
cmd_default() {
- # TODO: Refactor getting this prefix into a general function
- PREFIX=$(git config --get gitflow.prefix.release || echo release/)
+ cmd_list "$@"
+}
+
+cmd_list() {
RELEASE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
if [ -z "$RELEASE_BRANCHES" ]; then
warn "No release branches exist."
@@ -57,6 +53,16 @@
exit 0
}
+parse_args() {
+ VERSION="$1"
+ if [ "$VERSION" = "" ]; then
+ echo "Missing argument <version>."
+ usage
+ exit 1
+ fi
+ BRANCH=$PREFIX$VERSION
+}
+
cmd_start() {
parse_args "$@"