Skip to content

Commit

Permalink
variables split - cli
Browse files Browse the repository at this point in the history
  • Loading branch information
mpapis committed Sep 15, 2011
1 parent c2cce58 commit 09984df
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 62 deletions.
10 changes: 7 additions & 3 deletions core/cli/shell/dev/functions
Expand Up @@ -83,7 +83,8 @@ sm_development_update()

extension_package()
{
typeset _name="${1:-}" _path _version file _archiver
typeset _name _path _version file _archiver
_name="${1:-}"
shift || __sm.log.fail "Cannot package an extension; no extension name was given."

_path="${extensions_development_path:-"$extensions_src_path"}"
Expand Down Expand Up @@ -123,7 +124,8 @@ extension_package()

extension_publish()
{
typeset _name="${1:-}" _path _version _file
typeset _name _path _version _file
_name="${1:-}"
shift || __sm.log.fail "Cannot publish an extension; no extension name was given."

NIY "Extension publishing locally and to extensions.beginrescueend.com has not yet been implemented."
Expand Down Expand Up @@ -156,7 +158,9 @@ extension_publish()

extension_module_add()
{
typeset _extension="${1}" _module="${2}" _path
typeset _extension _module _path
_extension="${1}"
_module="${2}"
_path="${3:-"${extensions_development_path}/${_extension}"}"

if ! files contain string "${_module}" "${_path}/shell/includes"
Expand Down
22 changes: 14 additions & 8 deletions core/cli/shell/ext/functions
Expand Up @@ -28,7 +28,8 @@ ext_help()

ext_list()
{
typeset extensions COLUMNS=80
typeset extensions
true ${COLUMNS:=80}

if __sm.extension.in "${exts_system_path}/active"
then
Expand All @@ -52,7 +53,7 @@ ext_list()

ext_list_known()
{
typeset COLUMNS=80
true ${COLUMNS:=80}

printf "# %18s | %s\n" "Extension name" "Repository"

Expand All @@ -64,7 +65,9 @@ ext_list_known()

ext_install()
{
typeset _name _names="$1" _uri="$2"
typeset _name _names _uri
_names="$1"
_uri="$2"
shift || __sm.log.fail "No extension name was given."

_names=(${_names//,/ })
Expand All @@ -82,7 +85,8 @@ ext_install()

ext_install_all()
{
typeset _ext _name _uri COLUMNS=80
typeset _ext _name _uri
true ${COLUMNS:=80}
while read _ext
do
[[ "${line}" != \#* ]] || continue
Expand Down Expand Up @@ -129,7 +133,8 @@ ext_update()

ext_update_all()
{
typeset _name _entries=( "${exts_user_path}"/* )
typeset _name _entries
_entries=( "${exts_user_path}"/* )

if (( ! "${#_entries[@]}" ))
then
Expand All @@ -145,7 +150,8 @@ ext_update_all()

ext_uninstall()
{
typeset _name="$1"
typeset _name
_name="$1"
case "${_name}" in
*/*|.|..)
__sm.log.error "Please specify a valid extension name."
Expand All @@ -168,7 +174,8 @@ ext_uninstall()

ext_check_availability()
{
typeset _ext _line _args=($@)
typeset _ext _line _args
_args=($@)

# TODO: refactor this to take argument of uri to check instead.
# provide check_known_exts_availability or some such to wrap this.
Expand All @@ -189,4 +196,3 @@ ext_check_availability()
esac
done < "${sm_path}/core/cli/config/known_ext"
}

12 changes: 7 additions & 5 deletions core/cli/shell/functions
Expand Up @@ -3,7 +3,8 @@
#TODO: this code should be distributed to proper places
extension_cli()
{
typeset _ignored_args=() _string _token
typeset _ignored_args _string _token
_ignored_args=()

number_of_args=${#extension_args[@]}

Expand Down Expand Up @@ -44,7 +45,8 @@ extension_cli()
#
actions()
{
typeset _action="$1"
typeset _action _token
_action="$1"
shift || __sm.log.fail "Actions command not given."

while (( $# ))
Expand Down Expand Up @@ -72,12 +74,12 @@ actions()

__sm.actions.maps.build()
{
typeset _path _paths=($@) _extensions
for _path in "${_paths[@]}"
NIY
typeset _path _extensions
for _path in "$@"
do
_extensions=()
done

}


13 changes: 8 additions & 5 deletions core/cli/shell/get/functions
Expand Up @@ -8,7 +8,8 @@ fetch_version()

md5_match()
{ # TODO: switch this to using system module's os_* DSL
typeset _archive="$1" _path
typeset _archive _path
_archive="$1"

if command exists md5
then
Expand Down Expand Up @@ -81,14 +82,17 @@ Halting installation.

install_remote()
{
typeset remote="${1:-sm}"

typeset remote
remote="${1:-sm}"
install_sm_scm "$(scm_identifier "$remote")" "$remote"
}

install_sm_scm()
{
typeset remote="origin" dir="${1}" repo="${2:-sm}"
typeset remote dir repo
remote="origin"
dir="${1}"
repo="${2:-sm}"

__sm.includes api/vcs

Expand All @@ -103,4 +107,3 @@ install_sm_scm()

exec bash ${PWD}/install --trace="$trace_flags" --debug="$debug_flags"
}

14 changes: 8 additions & 6 deletions core/cli/shell/man/functions
Expand Up @@ -2,10 +2,12 @@

detect_man()
{
typeset _extensions_path=$1 _extension=$2
typeset _extensions_path _extension _man_path _man_name _man_paths
_extensions_path=$1
_extension=$2
shift

typeset _man_path _man_name="$*" #include extension in name
_man_name="$*" #include extension in name
shift

_man_name="${_man_name:-cli}"
Expand All @@ -26,7 +28,7 @@ detect_man()
return 1
fi

typeset _man_paths=( ${_extensions_path}/${_extension}/man/man*/${_man_name}* )
_man_paths=( ${_extensions_path}/${_extension}/man/man*/${_man_name}* )
if (( ${#_man_paths[@]} ))
then
man_file="${_man_paths[__sm_array_start]}"
Expand All @@ -37,7 +39,7 @@ detect_man()

man_display()
{
typeset man_path man_params man_number
typeset man_path man_params man_number status _man_name

if echo $1 | grep -E '^[0-9]+$' >/dev/null
then
Expand All @@ -50,7 +52,7 @@ man_display()
then
if ! man $man_file
then
typeset status=$?
status=$?
case $status in
(16)
#Not found page - ignore
Expand All @@ -60,7 +62,7 @@ man_display()
esac
fi
else
typeset _man_name="$*"
_man_name="$*"
_man_name="${_man_name:-cli}"
_man_name="${_man_name// /_}"
log "Could not find man page for ${_man_name}${man_number:+.${man_number}}"
Expand Down
24 changes: 13 additions & 11 deletions core/cli/shell/module_utils/functions
Expand Up @@ -14,16 +14,17 @@ modules_installed()

module_functions()
{
typeset _function _functions _modules="${@:-}"
typeset _function _functions _modules _path
_modules="${@:-}"

[[ -n "${_modules}" ]] ||
__sm.log.fail "Cannot print the functions for module(s); No module names given."

typeset _path="${__sm_modules_path}/${_module}"
_path="${__sm_modules_path}/${_module}"

_functions=($(
find "${_path}" -mindepth 1 -maxdepth 1 -name functions -type f -print0 |
xargs -0 grep '^[a-z_]*()$' 2>/dev/null || true
find "${_path}" -mindepth 1 -maxdepth 1 -name functions -type f -print0 |
xargs -0 grep '^[a-z_]*()$' 2>/dev/null || true
))

for _function in "${_functions[@]}"
Expand Down Expand Up @@ -83,7 +84,8 @@ module_docs()
__sm.log.fail "Cannot generate documentation for '${_module}';"\
" 'pygmentize' was not found in the PATH, install pygmentize and try again."

typeset _path="${core_development_path}/shell/${_module}"
typeset _path
_path="${core_development_path}/shell/${_module}"
if (( content_flag == 1 ))
then
shocco "${_path}/functions" |
Expand All @@ -102,9 +104,9 @@ modules_docgen()
# TODO: Replace with,
# for file in modules/*/functions ; do (name=${file%%\/functions}; shocco $file > html/${name//*\/}.html)& done ; wait

typeset _module _function _functions _name
typeset _prefix="${core_development_path}/html/shell"
typeset _path="${site_development_path}"
typeset _module _function _functions _name _prefix _path
_prefix="${core_development_path}/html/shell"
_path="${site_development_path}"

if [[ -n "${core_development_path}" ]]
then
Expand Down Expand Up @@ -170,9 +172,9 @@ modules_site_docgen()
# TODO: Replace with,
# for file in modules/*/functions ; do (name=${file%%\/functions}; shocco $file > html/${name//*\/}.html)& done ; wait

typeset _module _function _functions _name _file
typeset _prefix="${core_development_path}/html/shell"
typeset _path="${site_development_path}"
typeset _module _function _functions _name _file _prefix _path
_prefix="${core_development_path}/html/shell"
_path="${site_development_path}"

paths exists "${core_development_path}" ||
__sm.log.fail "Set core_development_path in ~/.smrc, to run docgen."
Expand Down
1 change: 0 additions & 1 deletion core/cli/shell/pkg/functions

This file was deleted.

33 changes: 21 additions & 12 deletions core/cli/shell/sets/functions
Expand Up @@ -27,7 +27,8 @@ sets_help()

sets_list()
{
typeset _path extensions COLUMNS=80
typeset _path extensions
true ${COLUMNS:=80}

for _path in "${extensions_search_paths[@]}"
do
Expand Down Expand Up @@ -59,7 +60,8 @@ sets_list()

sets_list_known()
{
typeset COLUMNS=80
typeset line
true ${COLUMNS:=80}
printf "# %18s | %s\n" "Set Name" "Repository"

while read line
Expand All @@ -70,10 +72,11 @@ sets_list_known()

sets_install()
{
typeset _name _names="${1:-}" _extension_namespace
typeset _name _names _extension_namespace
_names="${1:-}"
shift || __sm.log.fail "No set name was given."

_names=(${_names//,/ })
_names=( ${=_names//,/ } )
_extension_namespace="${sets_user_path#${sm_path}\/}"
_extension_namespace="${_extension_namespace#${sm_user_path}\/}"

Expand All @@ -85,18 +88,19 @@ sets_install()

set_install()
{
typeset _name="${1:-}"
typeset _name _uri _identifier _version
_name="${1:-}"
shift || __sm.log.fail "No set name was given."

typeset _uri="${1:-}"
_uri="${1:-}"
shift || _uri=$( awk -F= "/^${_name}=/ {print \$2 }" < "${sm_path}/core/cli/config/known_sets" | tail -n 1 )

[[ -n "${_uri}" ]] ||
__sm.log.error "uri not given and cannot find ${_name} in known extension sets."

typeset _identifier="$(scm_identifier "${_uri}")"
_identifier="$(scm_identifier "${_uri}")"

typeset _version="head"
_version="head"
if [[ "${_name}" == *:* ]]
then
_version="${_name/*:}"
Expand All @@ -117,7 +121,9 @@ set_install()

sets_install_all()
{
typeset _set _name _uri COLUMNS=80
typeset _set _name _uri
true ${COLUMNS:=80}

while read _set
do
[[ "${line}" != \#* ]] || continue
Expand Down Expand Up @@ -164,7 +170,8 @@ sets_update()

sets_update_all()
{
typeset _name _sets=( "${sets_user_path}"/active/* )
typeset _name _sets
_sets=( "${sets_user_path}"/active/* )

if (( ! ${#_sets[@]} ))
then
Expand All @@ -180,7 +187,8 @@ sets_update_all()

sets_uninstall()
{
typeset _name="$1"
typeset _name
_name="$1"
case "${_name}" in
*/*|.|..)
__sm.log.error "Please specify a valid extension name."
Expand All @@ -203,7 +211,8 @@ sets_uninstall()

sets_check_availability()
{
typeset _set _line _args=($@)
typeset _set _line _args
_args=( $@ )

# TODO: refactor this to take argument of uri to check instead.
# provide check_known_sets_availability or some such to wrap this.
Expand Down

0 comments on commit 09984df

Please sign in to comment.