Skip to content

Commit

Permalink
added unlink functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr Kucherenko committed Jan 5, 2024
1 parent eb5391f commit ff8f60b
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 80 deletions.
25 changes: 16 additions & 9 deletions .scripts/_arguments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
## License: MIT
## Source: https://github.com/OleksandrKucherenko/e-bash

# one time initialization, CUID
[[ "${clr0ljyne0004og38nhbnvpal}" == "yes" ]] && return 0 || export clr0ljyne0004og38nhbnvpal="yes"

# shellcheck disable=SC1090 source=_logger.sh
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/_logger.sh"

Expand Down Expand Up @@ -71,7 +74,7 @@ function parse:extract_output_definition() {
function parse:mapping() {
local args=("$@")

# TODO (olku): trim whitespaces in $ARGS_DEFINITION, not spaces in begining or end, no double spaces
# TODO (olku): trim whitespaces in $ARGS_DEFINITION, no spaces in beginning or end, no double spaces
echo:Common "${cl_grey}Definition: $ARGS_DEFINITION${cl_reset}" >&2

# extract definition of each argument, separated by space, remove last empty element
Expand All @@ -80,7 +83,7 @@ function parse:mapping() {
# build lookup map of arguments, extract the longest name of each argument
declare -A -g lookup_arguments && lookup_arguments=() # key-to-index_of_definition. e.g. -c -> 0, --cookies -> 0
declare -A -g index_to_outputs && index_to_outputs=() # index-to-variable_name, e.g. -c,--cookies -> 0=cookies
declare -A -g index_to_args_qt && index_to_args_qt=() # index-to-argument_qauntity, e.g. -c,--cookies -> 0="0"
declare -A -g index_to_args_qt && index_to_args_qt=() # index-to-argument_quantity, e.g. -c,--cookies -> 0="0"
declare -A -g index_to_default && index_to_default=() # index-to-argument_default, e.g. -c,--cookies -> 0="", -c=:default:1 -> 0="default"

# build parameters mapping
Expand Down Expand Up @@ -213,8 +216,8 @@ function parse:arguments() {
}

# global associative array for flag-to-description mapping
if [ -z "$args_to_description" ]; then declare -A -g args_to_description && args_to_description=(); fi
if [ -z "$args_to_group" ]; then declare -A -g args_to_group && args_to_group=(); fi
if [ -z "$args_to_description" ]; then declare -A -g args_to_description=(); fi
if [ -z "$args_to_group" ]; then declare -A -g args_to_group=(); fi

function parse:descr() {
local flag=$1
Expand All @@ -230,7 +233,7 @@ function parse:descr() {
function print:help() {
# if multiple groups defined in $args_to_group then print each group separately
if [ ${#args_to_group[@]} -gt 1 ]; then
: # TODO (olku): implement me
: # TODO (olku): implement me, compose HELP documentation from definitions
fi

# print help for each argument
Expand All @@ -242,10 +245,14 @@ function print:help() {
${__SOURCED__:+return}

logger common "$@" # register own logger
parse:exclude_flags_from_args "$@"
parse:arguments "$@"

# common descriptions for argumetns
logger loader "$@" # initialize logger
echo:Loader "loaded: ${cl_grey}${BASH_SOURCE[0]}${cl_reset}"

parse:exclude_flags_from_args "$@" # pre-filter arguments from flags
parse:arguments "$@" # parse arguments and assign them to output variables

# common descriptions for arguments
parse:descr "-h" "Print utility help"
parse:descr "--debug" "Force debug output of the tool"
parse:descr "-v" "Display tool version"
parse:descr "-v" "Display tool version and exit"
3 changes: 3 additions & 0 deletions .scripts/_commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
## License: MIT
## Source: https://github.com/OleksandrKucherenko/e-bash

# one time initialization, CUID
[[ "${clr0lkjrz0005og383aivno77}" == "yes" ]] && return 0 || export clr0lkjrz0005og383aivno77="yes"

# is allowed to use macOS extensions (script can be executed in *nix second)
use_macos_extensions=false
if [[ "$OSTYPE" == "darwin"* ]]; then use_macos_extensions=true; fi
Expand Down
23 changes: 5 additions & 18 deletions .scripts/_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
## License: MIT
## Source: https://github.com/OleksandrKucherenko/e-bash

# one time initialization, CUID
[[ "${clr0ll9d90006og38jx5kjlnj}" == "yes" ]] && return 0 || export clr0ll9d90006og38jx5kjlnj="yes"

# shellcheck disable=SC1090 source=./_commons.sh
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/_commons.sh"
# shellcheck disable=SC1090 source=./_logger.sh
Expand Down Expand Up @@ -137,24 +140,8 @@ ${__SOURCED__:+return}

logger dependencies "$@" # register own debug tag & logger functions

# Tests:
#dependency bash "5.0.18(1)-release" "brew install bash" "--version"
#dependency bash "5.0.[0-9]{2}(1)-release" "brew install bash" "--version"
#dependency bash "5.0.*(1)-release" "brew install bash" "--version"
#dependency bash "5.*.*(1)-release" "brew install bash" "--version"
#dependency bash "5.*.*" "brew install bash" "--version" --debug # print debug info
#dependency bash "5.*.*" "brew install bash" "--version" 0 # ignore $5 parameter
#dependency git "2.*.*" "brew install git" "--version"
#dependency bazelisk "4.*.*" "brew install bazel" "--version"
#dependency yq "4.13.2" "brew install yq" "-V"
#dependency jq "1.6" "brew install jq"
#dependency bash "[45].*.*" "brew install bash" # allow 4.xx and 5.xx versions
#dependency go "1.17.*" "brew install go" "version"
#dependency buildozer "redacted" "go get github.com/bazelbuild/buildtools/buildozer" "-version" 1
#dependency buildozer "redacted" "go get github.com/bazelbuild/buildtools/buildozer"
#dependency go "1.17.*" "brew install go && (echo 'export GOPATH=\$HOME/go; export PATH=\$GOPATH/bin:\$PATH;' >> ~/.zshrc)" "version"
#dependency go "2.17.*" "echo 'export GOPATH=\$HOME/go; export PATH=\$GOPATH/bin:\$PATH;'" "version" --exec
#dependency go "2.17.*" "echo 'export GOPATH=\$HOME/go; export PATH=\$GOPATH/bin:\$PATH;' >> ~/.zshrc" "version" --debug
logger loader "$@" # initialize logger
echo:Loader "loaded: ${cl_grey}${BASH_SOURCE[0]}${cl_reset}"

# ref:
# https://docs.gradle.org/current/userguide/single_versions.html
Expand Down
10 changes: 10 additions & 0 deletions .scripts/_logger.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
## License: MIT
## Source: https://github.com/OleksandrKucherenko/e-bash

# one time initialization, CUID
[[ "${clr0li2550002og38iiryffm8}" == "yes" ]] && return 0 || export clr0li2550002og38iiryffm8="yes"

# declare global associative array
if [[ -z $TAGS ]]; then declare -g -A TAGS; fi
if [[ -z $TAGS_PREFIX ]]; then declare -g -A TAGS_PREFIX; fi
Expand Down Expand Up @@ -64,6 +67,9 @@ function logger() {
local suffix=${1^}
# local suffix=$(echo "$1" | sed -e "s/\b\(.\)/\u\1/g")

# check if logger already exists, then skip
if type "echo:${suffix}" &>/dev/null; then return 0; fi

# keep it disabled by default
TAGS+=([$tag]=0)

Expand All @@ -86,6 +92,7 @@ function logger() {
}

# save current $TAGS state
# bashsupport disable=BP2001
function logger:push() {
TAGS_STACK=$((TAGS_STACK + 1))
local new_stack="__TAGS_STACK_$TAGS_STACK"
Expand Down Expand Up @@ -113,3 +120,6 @@ function logger:pop() {
# This is the writing style presented by ShellSpec, which is short but unfamiliar.
# Note that it returns the current exit status (could be non-zero).
${__SOURCED__:+return}

logger loader "$@" # initialize logger
echo:Loader "loaded: ${cl_grey}${BASH_SOURCE[0]}${cl_reset}"
Loading

0 comments on commit ff8f60b

Please sign in to comment.