Skip to content

Instantly share code, notes, and snippets.

@egg82
Created October 11, 2022 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egg82/3824a2f9c188b9a2cd4b854f1bc5e702 to your computer and use it in GitHub Desktop.
Save egg82/3824a2f9c188b9a2cd4b854f1bc5e702 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
export INFO_ENABLED=true
export DEBUG_ENABLED=true
export TMP_DIR="/tmp/commander"
if [[ -d "${TMP_DIR}" ]]; then
rm -rf "${TMP_DIR}"
fi
mkdir -p "${TMP_DIR}"
# shellcheck source=./lang.sh
source "./lang.sh"
# shellcheck source=./functions.sh
source "./functions.sh"
from () {
local namespace="${1}"
local from_type="${2}"
local from_name="${3}"
if [[ "${from_type}" = "import" ]]; then
import "${namespace}.${from_name}"
else
print 3 "$(lang_transform "${LANG_FROM_TYPE_NOT_RECOGNIZED}" "{type}" "${from_type}")"
return 1
fi
}
import () {
local r_import="(.*)[/ \.](.*)"
local namespace=""
local import_name="${1}"
if [[ "${import_name}" =~ ${r_import} ]]; then
namespace="${BASH_REMATCH[1]}"
import_name="${BASH_REMATCH[2]}"
fi
if [[ -n "${namespace}" ]]; then
print 0 "import ${namespace}.${import_name}"
download_file "${namespace}/${import_name}"
source "${import_name}"
else
print 0 "import ${import_name}"
download_file "${import_name}"
source "${import_name}"
fi
}
import "test"
import "testing.testy"
import "blah testies"
from "" import "test"
from "testing" import "testy"
from "" blah "blargh"
from "blah" import "testies"
#register "test" "value"
#register "testing.testy" "blah"
#register "testing.testy2" "blargh"
#retrieve "test"
#retrieve "testing\.testy"
#retrieve "testing\..*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment