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-feature b/git-flow-feature
index 6f3a0bb..8060d47 100644
--- a/git-flow-feature
+++ b/git-flow-feature
@@ -13,7 +13,7 @@
#
usage() {
- echo "usage: git flow feature"
+ echo "usage: git flow feature [list]"
echo " git flow feature start <name> [<base>]"
echo " git flow feature finish <name> [<base>]"
echo " git flow feature publish <name>"
@@ -34,21 +34,16 @@
#echo "--push Push to the origin repo when finished"
}
-parse_args() {
- NAME="$1"
- BASE="${2:-$DEVELOP_BRANCH}"
- if [ "$NAME" = "" ]; then
- echo "Missing argument <name>."
- usage
- exit 1
- fi
+# setup will always be called before the actual cmd_* functions
+setup() {
PREFIX=$(git config --get gitflow.prefix.feature || echo feature/)
- BRANCH=$PREFIX$NAME
}
cmd_default() {
- # TODO: Refactor getting this prefix into a general function
- PREFIX=$(git config --get gitflow.prefix.feature || echo feature/)
+ cmd_list "$@"
+}
+
+cmd_list() {
FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
if [ -z "$FEATURE_BRANCHES" ]; then
warn "No feature branches exist."
@@ -62,6 +57,18 @@
exit 0
}
+parse_args() {
+ NAME="$1"
+ BASE="${2:-$DEVELOP_BRANCH}"
+ if [ "$NAME" = "" ]; then
+ echo "Missing argument <name>."
+ usage
+ exit 1
+ fi
+ PREFIX=$(git config --get gitflow.prefix.feature || echo feature/)
+ BRANCH=$PREFIX$NAME
+}
+
cmd_start() {
parse_args "$@"