[gedit/wip/3.14-osx: 41/69] [osx] Add help to the build script



commit b61ae3602e9c94bcb79efb767a40a2896e01213a
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Mon Aug 25 09:21:07 2014 +0200

    [osx] Add help to the build script

 osx/build/build |  121 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 116 insertions(+), 5 deletions(-)
---
diff --git a/osx/build/build b/osx/build/build
index b58febb..25e1d77 100755
--- a/osx/build/build
+++ b/osx/build/build
@@ -13,6 +13,8 @@ INSTALLD="$HOMED/.local"
 GTK_OSX_BASE_URL="https://git.gnome.org/browse/gtk-osx/plain/";
 JHBUILD_SOURCED="$SOURCED/jhbuild"
 
+ME="$0"
+
 if [ -z "$GEDIT_SDK" ]; then
        export GEDIT_SDK=10.7
 fi
@@ -20,7 +22,7 @@ fi
 export PATH="$INSTALLD/bin:$PATH"
 
 function do_exit() {
-       echo "$1"
+       printf "$@"
        exit 1
 }
 
@@ -70,6 +72,10 @@ function setup_jhbuildrc() {
     ln -s "$D/config/jhbuildrc-gedit" "$HOMED/.jhbuildrc-gedit" || exit 1
 }
 
+function init_help_short() {
+       echo "Initialize the in-tree build environment (installs jhbuild)"
+}
+
 function cmd_init() {
        mkdir -p "$SOURCED"
 
@@ -84,6 +90,10 @@ function cmd_init() {
        ln -s $(cd "$D/../../" && pwd) "$BASED/$GEDIT_SDK/source/gedit"
 }
 
+function bootstrap_help_short() {
+       echo "Run jhbuild bootstrap"
+}
+
 function cmd_bootstrap() {
        # Built python once
        cmd_jh bootstrap -q python || exit 1
@@ -97,6 +107,14 @@ function cmd_bootstrap() {
        cmd_jh bootstrap -q || exit 1
 }
 
+function jh_help_usage() {
+       echo "jhbuild-command ..."
+}
+
+function jh_help_short() {
+       echo "Run jhbuild commands"
+}
+
 function cmd_jh() {
        # Setup our jhbuild environment
        export GEDIT_OSX_SOURCE_BASE="$D"
@@ -114,26 +132,57 @@ function cmd_jh() {
        "$INSTALLD/bin/jhbuild" -f "$HOMED/.jhbuildrc" "$@"
 }
 
+function jhdbg_help_usage() {
+       echo "jhbuild command ..."
+}
+
+function jhdbg_help_short() {
+       echo "Run jhbuild commands in a debug environment"
+}
+
 function cmd_jhdbg() {
        export GEDIT_OSX_DEBUG=1
        cmd_jh "$@"
 }
 
+function shell_help_short() {
+       echo "Start the jhbuild shell (shorthand for jh shell)"
+}
+
 function cmd_shell() {
        cmd_jh shell
 }
 
+function make_help_usage() {
+       echo "module-source-directory"
+}
+
+function make_help_short() {
+       echo "Run jhbuild make at the provided source directory"
+}
+
 function cmd_make() {
        cd "$BASED/$GEDIT_SDK/source/$1" && cmd_jh make
 }
 
+function run_help_usage() {
+       echo "program ..."
+}
+
+function run_help_short() {
+       echo "Run the provided program in the jhbuild environment (shorthand for jh run)"
+}
+
 function cmd_run() {
        cmd_jh run "$@"
 }
 
+function all_help_short() {
+       echo "Runs the init, bootstrap and build commands"
+}
+
 function cmd_all() {
        if [ ! -d "$JHBUILD_SOURCED" ]; then
-               echo "init..."
                cmd_init || exit 1
        fi
 
@@ -145,22 +194,84 @@ function cmd_all() {
        cmd_jh build -q
 }
 
+function help_help_short() {
+       echo "Shows this help message"
+}
+
+function cmd_help() {
+       if [ -z "$1" ]; then
+               echo "Usage: $ME [command]"
+               echo ""
+               echo "Available commands:"
+               echo ""
+
+               for cmd in "${commands[ ]}"; do
+                       printf "  \033[1m$cmd\x1B[0m "
+
+                       l=${#cmd}
+                       let d="$commandsmaxlen - $l + 1"
+
+                       printf "%${d}s" ""
+                       echo -n "- "
+
+                       if [[ $(type -t "${cmd}_help_short") = "function" ]]; then
+                               "${cmd}_help_short"
+                       else
+                               echo ""
+                       fi
+               done
+
+               echo ""
+       else
+               cmd="cmd_$1"
+
+               if [[ $(type -t "$cmd") != "function" ]]; then
+                       do_exit "Invalid command \033[1m$1\033[0m, available commands are: $cmds\n"
+               fi
+
+               printf "Usage: $ME \033[1m$1\033[0m "
+
+               if [[ $(type -t "$1_help_usage") = "function" ]]; then
+                       "$1_help_usage"
+               else
+                       echo ""
+               fi
+
+               echo ""
+
+               if [[ $(type -t "$1_help_long") != "function" ]]; then
+                       "$1_help_short"
+               else
+                       "$1_help_long"
+               fi
+       fi
+}
+
 commands=()
+commandsmaxlen=0
 
 while read line
 do
        cmd=${line#declare -f }
 
        if [[ "$cmd" = cmd_* ]]; then
-               commands+=(${cmd#cmd_})
+               cname=${cmd#cmd_}
+
+               commands+=($cname)
+
+               l=${#cname}
+
+               if [[ $l > $commandsmaxlen ]]; then
+                       commandsmaxlen=$l
+               fi
        fi
 done < <(declare -F)
 
-cmds=$(printf ", %s" "${commands[ ]}")
+cmds=$(printf ", \033[1m%s\033[0m" "${commands[ ]}")
 cmds=${cmds:2}
 
 if [ -z "$1" ]; then
-       cmd_all
+       cmd_help
        exit 0
 fi
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]