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-support b/git-flow-support
index adb336d..fe7ce17 100644
--- a/git-flow-support
+++ b/git-flow-support
@@ -13,10 +13,32 @@
#
usage() {
- echo "usage: git flow support"
+ echo "usage: git flow support [list]"
echo " git flow support start <version> [<base>]"
}
+setup() {
+ PREFIX=$(git config --get gitflow.prefix.support || echo support/)
+}
+
+cmd_default() {
+ cmd_list "$@"
+}
+
+cmd_list() {
+ SUPPORT_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
+ if [ -z "$SUPPORT_BRANCHES" ]; then
+ warn "No support branches exist."
+ exit 0
+ fi
+ echo "$SUPPORT_BRANCHES" | sed "s?^$PREFIX??g"
+}
+
+cmd_help() {
+ usage
+ exit 0
+}
+
parse_args() {
VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
VERSION="$1"
@@ -30,22 +52,6 @@
BRANCH=$PREFIX$VERSION
}
-cmd_default() {
- # TODO: Refactor getting this prefix into a general function
- PREFIX=$(git config --get gitflow.prefix.support || echo support/)
- SUPPORT_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
- if [ -z "$SUPPORT_BRANCHES" ]; then
- warn "No support branches exist."
- exit 0
- fi
- echo "$SUPPORT_BRANCHES" | sed "s?^$PREFIX??g"
-}
-
-cmd_help() {
- usage
- exit 0
-}
-
cmd_start() {
parse_args "$@"