From 616c4732951e6c06a2b7577a3025cce9e2e4fd74 Mon Sep 17 00:00:00 2001 From: Liu Dng Date: Sat, 9 Oct 2021 19:49:42 +0800 Subject: [PATCH] Support custom command name. --- advanced.bash | 10 +++++++--- compact.bash | 23 ++++++++++++----------- lib/framework.bash | 10 +++++++--- simple.bash | 4 ++-- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/advanced.bash b/advanced.bash index 9f3b827..e27baea 100755 --- a/advanced.bash +++ b/advanced.bash @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 2020 Liu Dng. All rights reserved. +# Copyright 2021 Liu Dng. All rights reserved. # Use of this source code is governed by Apache License # that can be found in the LICENSE file. @@ -10,7 +10,7 @@ set -o pipefail set -o errexit # The dev package version -declare -gr dev_global_version="1.0.0" +declare -gr dev_global_version="1.1.0" # The dev execution file path declare -gr dev_global_self="$(realpath $0)" @@ -18,6 +18,8 @@ declare -gr dev_global_self="$(realpath $0)" # The dev execution base path declare -gr dev_global_base="$(dirname $(dirname $dev_global_self))" +declare -g dev_command + declare -g dev_arg_key declare -g dev_arg_val @@ -90,13 +92,15 @@ dev_kernel_optional_arguments() { } dev_main() { + dev_command="body" + while [[ $# -gt 0 && "${1:0:1}" == "-" ]]; do dev_kernel_optional_arguments "$1" shift done [[ "$dev_global_trace" -eq "1" ]] && set -o xtrace - cmd_body $@ + cmd_$dev_command $@ } dev_main $@ diff --git a/compact.bash b/compact.bash index 38f0c42..1d348c0 100755 --- a/compact.bash +++ b/compact.bash @@ -1,36 +1,37 @@ #!/bin/bash -# Copyright 2020 Liu Dng. All rights reserved. +# Copyright 2021 Liu Dng. All rights reserved. # Use of this source code is governed by Apache License # that can be found in the LICENSE file. -. lib/framework.bash +. $(dirname $(realpath $0))/lib/framework.bash # # Declare custom global variables # +# +# Write your own source code here. +# cmd_body() { - # - # Write your own source code here. - # echo "This is a sample bash script." echo "--key = $demo_key" echo "Custom arguments: $@" + echo "dev_global_base: $dev_global_base" } +# +# Append your custom help here. +# dev_custom_help_usage() { - # - # Append your custom help here. - # echo " --key=value Example key and value" } +# +# Add custom optional arguments here. +# dev_custom_optional_arguments() { case "$dev_arg_key" in - # - # Add custom optional arguments here. - # --key) declare -gr demo_key="$dev_arg_val" ;; diff --git a/lib/framework.bash b/lib/framework.bash index c880d09..1d8564f 100644 --- a/lib/framework.bash +++ b/lib/framework.bash @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 2020 Liu Dng. All rights reserved. +# Copyright 2021 Liu Dng. All rights reserved. # Use of this source code is governed by Apache License # that can be found in the LICENSE file. @@ -10,7 +10,7 @@ set -o pipefail set -o errexit # The dev package version -declare -gr dev_global_version="1.0.0" +declare -gr dev_global_version="1.1.0" # The dev execution file path declare -gr dev_global_self="$(realpath $0)" @@ -18,6 +18,8 @@ declare -gr dev_global_self="$(realpath $0)" # The dev execution base path declare -gr dev_global_base="$(dirname $(dirname $dev_global_self))" +declare -g dev_command + declare -g dev_arg_key declare -g dev_arg_val @@ -65,6 +67,8 @@ dev_kernel_optional_arguments() { } dev_main() { + dev_command="body" + while [[ $# -gt 0 && "${1:0:1}" == "-" ]]; do dev_kernel_optional_arguments "$1" shift @@ -73,5 +77,5 @@ dev_main() { dev_custom_validation [[ "$dev_global_trace" -eq "1" ]] && set -o xtrace - cmd_body $@ + cmd_$dev_command $@ } diff --git a/simple.bash b/simple.bash index e777e0c..a7b444b 100755 --- a/simple.bash +++ b/simple.bash @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright 2020 Liu Dng. All rights reserved. +# Copyright 2021 Liu Dng. All rights reserved. # Use of this source code is governed by Apache License # that can be found in the LICENSE file. @@ -10,7 +10,7 @@ set -o pipefail set -o errexit # The dev package version -declare -gr dev_global_version="1.0.0" +declare -gr dev_global_version="1.1.0" # The dev execution file path declare -gr dev_global_self="$(realpath $0)"