Commit b61ae360 authored by Jesse van den Kieboom's avatar Jesse van den Kieboom

[osx] Add help to the build script

parent aa915026
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment