]> git.sur5r.net Git - ngadmin/blobdiff - cli/com_firmware.c
Let commands handle themselves absence of arguments
[ngadmin] / cli / com_firmware.c
index f697af699160461b354542cd95a64a80d3b0f299..d3e9d0df24f5bd94f83ebd8ea41fdb76a64dbebc 100644 (file)
@@ -1,64 +1,60 @@
 
-#include "common.h"
-
-
-
-
-static bool do_firmware_show (const struct TreeNode *tn UNUSED, int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
- const struct swi_attr *sa;
- bool ret=true;
- if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
-  printf("must be logged\n");
-  ret=false;
-  goto end;
- }
- puts(sa->firmware);
- end:
- return ret;
+#include "commands.h"
+
+
+bool do_firmware_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
+{
+       const struct swi_attr *sa;
+       bool ret = true;
+       
+       
+       if (argc > 0) {
+               printf("this command takes no argument\n");
+               ret = false;
+               goto end;
+       }
+       
+       sa = ngadmin_getCurrentSwitch(nga);
+       if (sa == NULL) {
+               printf("must be logged\n");
+               ret = false;
+               goto end;
+       }
+       
+       puts(sa->firmware);
+       
+end:
+       
+       return ret;
 }
 
 
-
-static bool do_firmware_upgrade (const struct TreeNode *tn UNUSED, int nb, const char **com UNUSED, struct ngadmin *nga) {
- const struct swi_attr *sa;
- bool ret=true;
- if ( nb!=1 ) {
-  printf("Usage: firmware upgrade <file>\n");
-  ret=false;
- }
- if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
-  printf("must be logged\n");
-  ret=false;
-  goto end;
- }
- printf("not implemented yet\n");
- end:
- return ret;
+bool do_firmware_upgrade (int argc, const char **argv, struct ngadmin *nga)
+{
+       const struct swi_attr *sa;
+       bool ret = true;
+       int i;
+       
+       
+       if (argc != 1) {
+               printf("usage: firmware upgrade <file>\n");
+               ret = false;
+               goto end;
+       }
+       
+       sa = ngadmin_getCurrentSwitch(nga);
+       if (sa == NULL) {
+               printf("must be logged\n");
+               ret = false;
+               goto end;
+       }
+       
+       i = ngadmin_upgradeFirmware(nga, argv[0]);
+       printErrCode(i);
+       
+end:
+       
+       return ret;
 }
 
 
-
-static const struct TreeNode com_firmware_show=COM("show", do_firmware_show, false, NULL);
-static const struct TreeNode com_firmware_upgrade=COM("upgrade", do_firmware_upgrade, true, NULL);
-
-const struct TreeNode com_firmware=COM("firmware", NULL, false, &com_firmware_show, &com_firmware_upgrade, NULL);
-
-
-