]> git.ipfire.org Git - people/arne_f/network.git/blobdiff - functions.cli
Fix weird device CLI command.
[people/arne_f/network.git] / functions.cli
index 9339a7bc2f0690b689dd9bf00cbb80bcde233201..a2ceb99e42df525c881fd3af9fcaeff95d69a550 100644 (file)
@@ -33,44 +33,32 @@ function cli_config() {
 }
 
 function cli_device() {
-       if device_config_exists ${1}; then
-               local device=${1}
-               local action=${2}
-               shift 2
+       local device=${1}
+       local action=${2}
+       shift 2
 
-               case "${action}" in
-                       down|up)
-                               device_${action} ${device} $@
-                               ;;
-               esac
-       else
-               local action=${1}
-               shift
+       assert device_exists ${device}
 
-               case "${action}" in
-                       create)
-                               device_${action} $@
-                               ;;
+       if zone_exists ${device} || port_exists ${device}; then
+               error "The device '${device}' has already been configured."
+               error "You cannot do a device action."
+               return ${EXIT_ERROR}
+       fi
 
-                       discover)
-                               echo "# XXX need to implement --raw here"
-                               local device
-                               for device in ${devices}; do
-                                       cli_device_discover ${device} $@
-                               done
-                               ;;
+       case "${action}" in
+               discover)
+                       echo "# XXX need to implement --raw here"
+                       cli_device_discover ${device} $@
+                       ;;
 
-                       show|"")
-                               local device
-                               for device in $(device_get $@); do
-                                       device_print ${device}
-                               done
-                               ;;
-                       *)
-                               cli_usage device
-                               ;;                              
-               esac
-       fi
+               show|"")
+                       # XXX device_show needs to be implemented
+                       device_show ${device}
+                       ;;
+               *)
+                       cli_usage device
+                       ;;
+       esac
 }
 
 function cli_device_discover() {
@@ -348,7 +336,8 @@ function cli_reset() {
                port_remove ${port}
        done
 
-       # XXX recreate ethernet ports
+       # Re-run the initialization functions
+       init_run
 
        exit ${EXIT_OK}
 }
@@ -505,3 +494,12 @@ function cli_yesno() {
 
        return ${EXIT_ERROR}
 }
+
+function cli_get_key() {
+       local key="${1%%=*}"
+       echo "${key/--/}"
+}
+
+function cli_get_val() {
+       echo "${1##*=}"
+}