}
function cli_device() {
- local action=${1}
- shift
-
- local device
- local devices=$@
-
- if [ -z "${devices}" ]; then
- devices=$(devices_get_all)
- fi
+ if device_config_exists ${1}; then
+ local device=${1}
+ local action=${2}
+ shift 2
- case "${action}" in
- discover)
- echo "# XXX need to implement --raw here"
- for device in ${devices}; do
- cli_device_discover ${device} $@
- done
- ;;
+ case "${action}" in
+ down|up)
+ device_${action} ${device} $@
+ ;;
+ esac
+ else
+ local action=${1}
+ shift
- show|"")
- for device in ${devices}; do
- cli_device_print ${device}
- done
- ;;
- *)
- cli_usage device
- ;;
- esac
-}
+ case "${action}" in
+ create)
+ device_${action} $@
+ ;;
-function cli_device_print() {
- local device=${1}
+ discover)
+ echo "# XXX need to implement --raw here"
+ local device
+ for device in ${devices}; do
+ cli_device_discover ${device} $@
+ done
+ ;;
- if ! device_exists ${device}; then
- error "Device '${device}' does not exist."
- return ${EXIT_ERROR}
+ show|"")
+ local device
+ for device in $(device_get $@); do
+ device_print ${device}
+ done
+ ;;
+ *)
+ cli_usage device
+ ;;
+ esac
fi
-
- echo "${device}"
- echo " Type: $(device_get_type ${device})"
- echo " Addr: $(device_get_address ${device})"
- echo
}
function cli_device_discover() {
[ "${up}" = "1" ] || device_set_down ${device}
}
+function cli_port() {
+ if cli_help_requested $@; then
+ cli_usage root-port
+ exit ${EXIT_OK}
+ fi
+
+ local action
+ local port
+
+ if port_exists ${1}; then
+ port=${1}
+ action=${2}
+ shift 2
+
+ # Action aliases
+ case "${action}" in
+ start)
+ action="up"
+ ;;
+ stop)
+ action="down"
+ ;;
+ show)
+ action="status"
+ ;;
+ esac
+
+ case "${action}" in
+ edit|up|down|status)
+ port_${action} ${port} $@
+ ;;
+ *)
+ error "Unrecognized argument: ${action}"
+ exit ${EXIT_ERROR}
+ ;;
+ esac
+ else
+ action=${1}
+ shift
+
+ case "${action}" in
+ create|destroy)
+ port_${action} $@
+ ;;
+ *)
+ error "Unrecognized argument: ${action}"
+ exit ${EXIT_ERROR}
+ ;;
+ esac
+ fi
+}
+
function cli_zone() {
if cli_help_requested $@; then
cli_usage root-zone
action=${2}
shift 2
+ # Action aliases
+ case "${action}" in
+ start)
+ action="up"
+ ;;
+ stop)
+ action="down"
+ ;;
+ show)
+ action="status"
+ ;;
+ esac
+
case "${action}" in
- config|down|edit|port|show|status|up)
+ config|down|edit|port|status|up)
zone_${action} ${zone} $@
;;
*)