@@ -329,6 +329,25 @@ int check1_validator(struct cli_def *cli, UNUSED(const char *name), UNUSED(const
329
329
return CLI_OK ;
330
330
}
331
331
332
+ int cmd_deep_dive (struct cli_def * cli , const char * command , char * argv [], int argc ) {
333
+ cli_print (cli , "Raw commandline was <%s>" , cli -> pipeline -> cmdline );
334
+ return CLI_OK ;
335
+ }
336
+
337
+ int int_validator (struct cli_def * cli , const char * name , const char * value ) {
338
+ // Verify 'value' is a positive number
339
+ long len ;
340
+ char * endptr ;
341
+ int rc = CLI_OK ;
342
+
343
+ printf ("int_validator called\n" );
344
+ errno = 0 ;
345
+ len = strtol (value , & endptr , 10 );
346
+ if ((endptr == value ) || (* endptr != '\0' ) || ((errno == ERANGE ) && ((len == LONG_MIN ) || (len == LONG_MAX ))))
347
+ return CLI_ERROR ;
348
+ return rc ;
349
+ }
350
+
332
351
int cmd_string (struct cli_def * cli , const char * command , char * argv [], int argc ) {
333
352
int i ;
334
353
cli_print (cli , "Raw commandline was <%s>" , cli -> pipeline -> cmdline );
@@ -340,6 +359,17 @@ int cmd_string(struct cli_def *cli, const char *command, char *argv[], int argc)
340
359
}
341
360
return CLI_OK ;
342
361
}
362
+ int cmd_long_name (struct cli_def * cli , const char * command , char * argv [], int argc ) {
363
+ int i ;
364
+ cli_print (cli , "Raw commandline was <%s>" , cli -> pipeline -> cmdline );
365
+ cli_print (cli , "Value for text argument is <%s>" , cli_get_optarg_value (cli , "text" , NULL ));
366
+
367
+ cli_print (cli , "Found %d 'extra' arguments after 'text' argument was processed" , argc );
368
+ for (i = 0 ; i != argc ; i ++ ) {
369
+ cli_print (cli , " Extra arg %d = <%s>" , i + 1 , argv [i ]);
370
+ }
371
+ return CLI_OK ;
372
+ }
343
373
344
374
void run_child (int x ) {
345
375
struct cli_command * c ;
@@ -448,6 +478,22 @@ void run_child(int x) {
448
478
cli_register_command (cli , NULL , "context" , cmd_context , PRIVILEGE_UNPRIVILEGED , MODE_EXEC ,
449
479
"Test a user-specified context" );
450
480
481
+ struct cli_command * d1 , * d2 , * d3 ;
482
+
483
+ d1 = cli_register_command (cli , NULL , "deep" , NULL , PRIVILEGE_UNPRIVILEGED , MODE_EXEC , "top level deep dive cmd" );
484
+ d2 = cli_register_command (cli , d1 , "dive" , NULL , PRIVILEGE_UNPRIVILEGED , MODE_EXEC , "mid level dep dive cmd" );
485
+ d3 = cli_register_command (cli , d2 , "cmd" , cmd_deep_dive , PRIVILEGE_UNPRIVILEGED , MODE_EXEC ,
486
+ "bottom level dep dive cmd" );
487
+ o = cli_register_optarg (d3 , "howdeep" , CLI_CMD_ARGUMENT , PRIVILEGE_UNPRIVILEGED , MODE_EXEC , "Specify how deep" , NULL ,
488
+ int_validator , NULL );
489
+ o = cli_register_optarg (d3 , "howlong" , CLI_CMD_OPTIONAL_ARGUMENT , PRIVILEGE_UNPRIVILEGED , MODE_EXEC ,
490
+ "Specify how long" , NULL , int_validator , NULL );
491
+
492
+ c = cli_register_command (
493
+ cli , NULL , "serioously_long_cammand_to_test_with" , cmd_long_name , PRIVILEGE_UNPRIVILEGED , MODE_EXEC ,
494
+ "show long command name with "
495
+ "newline\nand_a_really_long_line_that_is_much_longer_than_80_columns_to_show_that_wrap_case" );
496
+
451
497
cli_set_auth_callback (cli , check_auth );
452
498
cli_set_enable_callback (cli , check_enable );
453
499
// Test reading from a file
0 commit comments