-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel
executable file
·101 lines (89 loc) · 3.45 KB
/
model
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bash-utils
#
# This script is a module for Bash-Utils
#
# --------
#
# bash-utils - A *bash* library for better scripting
# <http://github.com/e-picas/bash-utils>
# Copyright (c) 2015 Pierre Cassat & contributors
#
# This program is free software: you can freely use it, redistribute it
# and/or modify it according to your needs, for yourself or a commercial use,
# under the terms of the Apache License version 2.0 (the "License") as
# published by the Apache Software Foundation.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# The sources of this program are hosted on a public repository.
# You can modify it, to ameliorate a feature or correct an error,
# inform about a bug and follow updates at <http://github.com/e-picas/bash-utils>.
#
# You should have received a copy of the License along with this program ;
# please see the LICENSE file that was distributed with this source code.
# If not, see <http://www.apache.org/licenses/LICENSE-2.0>.
#
#### COLORIZED CONTENTS #############################################################################
# models
export BASHUTILS_MODEL_DIRS="${BASH_UTILS_MODULES}/models/"
[ ! -d "$BASHUTILS_MODEL_DIRS" ] && error "models directory '$BASHUTILS_MODEL_DIRS' not found";
declare -a models_list=()
for f in "$BASHUTILS_MODEL_DIRS"/*; do
_f="$(basename "$f")"
models_list[${#models_list[@]}]="${_f%.model}"
done
# you can define here a string about module's usage (short synopsis), description, name and version
CMD_NAME='Model'
CMD_VERSION='0.0.1'
CMD_USAGE="model <type> [file_path]"
CMD_DESCRIPTION="See one of the bash models contents or copy it in 'file_path'"
CMD_HELP="arguments:
<type> model's type in: ${models_list[@]}
<file_path> if set, the model will be copied to that file
Use option '--dry-run' with the '<file_path>' argument to see what will be done first.
Use option '--quiet' without a '<file_path>' argument to get the model path.
";
CMD_ARGS=("${models_list[@]}")
set_env_array CMD_ARGS CMD_ARGS[@]
## !! REQUIRED !! ## stop here on pre-loading
if ${PRELOAD:-false}; then return 0; fi
#######################
## treat direct params ...
if [ -z "$CMD_MODULE" ]; then
[ "$(basename "$0")" = "$(basename "${BASH_SOURCE[0]}")" ] && exit 0 || return 0;
fi
[ $# -eq 0 ] && usage_info && exit 1;
rearrange_options "$@"
[ -n "$CMD_REQ" ] && eval set -- "$CMD_REQ";
common_options "$@"
$DEBUG && debug;
while [ $# -gt 0 ]; do
case "$1" in
-- ) shift; break;;
* ) ! is_known_option "$1" && error "unknown option '$1'";;
esac
shift
done
type="$1"
target=''
source=''
[ $# -gt 1 ] && target="$2"
source="${BASHUTILS_MODEL_DIRS}/${type}.model"
[ ! -f "$source" ] && error "undefined model type '$type'";
if [ -n "$target" ]; then
if $DRY_RUN; then
comment "cp '${source/$(pwd)\//}' '${target/$(pwd)\//}' && chmod a+x '${target/$(pwd)\//}'"
else
cp "$source" "$target"
chmod a+x "$target"
! $QUIET && echo "$target";
fi
else
if $QUIET; then echo "${source/$(pwd)\//}"; else cat "$source"; fi
fi
[ "$(basename "$0")" = "$(basename "${BASH_SOURCE[0]}")" ] && exit 0 || return 0;
# vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=sh