Skip to content

Commit

Permalink
Support custom command name.
Browse files Browse the repository at this point in the history
  • Loading branch information
liudng committed Oct 9, 2021
1 parent 5daf6db commit 616c473
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
10 changes: 7 additions & 3 deletions advanced.bash
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -10,14 +10,16 @@ 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)"

# 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
Expand Down Expand Up @@ -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 $@
23 changes: 12 additions & 11 deletions compact.bash
Original file line number Diff line number Diff line change
@@ -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"
;;
Expand Down
10 changes: 7 additions & 3 deletions lib/framework.bash
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -10,14 +10,16 @@ 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)"

# 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
Expand Down Expand Up @@ -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
Expand All @@ -73,5 +77,5 @@ dev_main() {
dev_custom_validation

[[ "$dev_global_trace" -eq "1" ]] && set -o xtrace
cmd_body $@
cmd_$dev_command $@
}
4 changes: 2 additions & 2 deletions simple.bash
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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)"
Expand Down

0 comments on commit 616c473

Please sign in to comment.