Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

69 lines (66 sloc) 1.876 kB
#!/bin/sh
command()
{
trace_filter command || set -o xtrace
local _command _subcommand _token _user _code _flags
_flags=()
while (( $# ))
do
_token="$1" && shift
case "${_token}" in
(exists)
if __sm.command.exists "${1}" > /dev/null 2>&1
then return 0 ; else return 1 ; fi
;;
(is)
_subcommand="$1"
shift || __sm.log.fail "A command must follow keyword 'is'; <function>"
case "${_subcommand}" in
(function)
if __sm.command.is.function "$1" >/dev/null 2>&1
then return 0 ; else return 1 ; fi
;;
# (script)
# (binary)
(*)
__sm.log.fail "Unknown command '${1}' following keyword 'is'"
;;
esac
;;
(full)
_subcommand="$1"
shift || __sm.log.fail "A 'command full' must follow keyword 'name'."
case "${_subcommand}" in
(name)
if __sm.command.full.name "$1" >/dev/null 2>&1
then return 0 ; else return 1 ; fi
;;
(*)
shift || __sm.log.fail "A 'command full' must follow keyword 'name'."
;;
esac
;;
(run)
case "$1" in
(as)
shift
_user="$1"
shift || __sm.log.fail "A user name or id must be specified after keyword 'as'"
# TODO: Check to ensure user name/id exists on the system
if __sm.command.run.as "${_user}" "${_flags[*]}" "$@"
then return 0 ; else return 1 ; fi
;;
(*)
_command="$1"
shift
if __sm.command.run "${_command}" "$@"
then return 0 ; else return 1 ; fi
;;
esac
;;
(*)
__sm.log.fail "Unknown command '${_token}'."
;;
esac
done
}
Jump to Line
Something went wrong with that request. Please try again.