Skip to content

Commit 1d3d6ed

Browse files
authored
Merge pull request #57 from dparrish/V1.10.3
V1.10.3 merge
2 parents 359ddb6 + 242b3fd commit 1d3d6ed

File tree

5 files changed

+324
-174
lines changed

5 files changed

+324
-174
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PREFIX = /usr/local
1111

1212
MAJOR = 1
1313
MINOR = 10
14-
REVISION = 2
14+
REVISION = 3
1515
LIB = libcli.so
1616
LIB_STATIC = libcli.a
1717

clitest.c

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <string.h>
1616
#include <strings.h>
1717
#include <unistd.h>
18+
1819
#include "libcli.h"
1920

2021
// vim:sw=4 tw=120 et
@@ -265,8 +266,8 @@ int shape_transient_eval(struct cli_def *cli, const char *name, const char *valu
265266
return CLI_ERROR;
266267
}
267268

268-
const char *KnownColors[] = {"black", "white", "gray", "red", "blue",
269-
"green", "lightred", "lightblue", "lightgreen", "darkred",
269+
const char *KnownColors[] = {"black", "white", "gray", "red", "blue",
270+
"green", "lightred", "lightblue", "lightgreen", "darkred",
270271
"darkblue", "darkgreen", "lavender", "yellow", NULL};
271272

272273
int color_completor(struct cli_def *cli, const char *name, const char *word, struct cli_comphelp *comphelp) {
@@ -306,6 +307,10 @@ int side_length_validator(struct cli_def *cli, const char *name, const char *val
306307
return rc;
307308
}
308309

310+
int transparent_validator(struct cli_def *cli, const char *name, const char *value) {
311+
return strcasecmp("transparent", value) ? CLI_ERROR : CLI_OK;
312+
}
313+
309314
int check1_validator(struct cli_def *cli, UNUSED(const char *name), UNUSED(const char *value)) {
310315
char *color;
311316
char *transparent;
@@ -324,6 +329,18 @@ int check1_validator(struct cli_def *cli, UNUSED(const char *name), UNUSED(const
324329
return CLI_OK;
325330
}
326331

332+
int cmd_string(struct cli_def *cli, const char *command, char *argv[], int argc) {
333+
int i;
334+
cli_print(cli, "Raw commandline was <%s>", cli->pipeline->cmdline);
335+
cli_print(cli, "Value for text argument is <%s>", cli_get_optarg_value(cli, "text", NULL));
336+
337+
cli_print(cli, "Found %d 'extra' arguments after 'text' argument was processed", argc);
338+
for (i = 0; i != argc; i++) {
339+
cli_print(cli, " Extra arg %d = <%s>", i + 1, argv[i]);
340+
}
341+
return CLI_OK;
342+
}
343+
327344
void run_child(int x) {
328345
struct cli_command *c;
329346
struct cli_def *cli;
@@ -367,33 +384,40 @@ void run_child(int x) {
367384

368385
// Register some commands/subcommands to demonstrate opt/arg and buildmode operations
369386

370-
c = cli_register_command(cli, NULL, "perimeter", cmd_perimeter, PRIVILEGE_UNPRIVILEGED, MODE_EXEC,
371-
"Calculate perimeter of polygon\nhas embedded newline\nand_a_really_long_line_that_is_much_longer_than_80_columns_to_show_that_wrap_case");
372-
cli_register_optarg(c, "transparent", CLI_CMD_OPTIONAL_FLAG, PRIVILEGE_UNPRIVILEGED, MODE_EXEC,
373-
"Set transparent flag", NULL, NULL, NULL);
374-
cli_register_optarg(c, "verbose", CLI_CMD_OPTIONAL_FLAG | CLI_CMD_OPTION_MULTIPLE, PRIVILEGE_UNPRIVILEGED, MODE_EXEC,
375-
"Set verbose flagwith some humongously long string \nwithout any embedded newlines in it to test with", NULL, NULL, NULL);
387+
c = cli_register_command(
388+
cli, NULL, "perimeter", cmd_perimeter, PRIVILEGE_UNPRIVILEGED, MODE_EXEC,
389+
"Calculate perimeter of polygon\nhas embedded "
390+
"newline\nand_a_really_long_line_that_is_much_longer_than_80_columns_to_show_that_wrap_case");
391+
o = cli_register_optarg(c, "transparent", CLI_CMD_OPTIONAL_FLAG, PRIVILEGE_UNPRIVILEGED, MODE_EXEC,
392+
"Set transparent flag", NULL, NULL, NULL);
393+
cli_optarg_addhelp(o, "transparent", "(any case)set to transparent");
394+
395+
cli_register_optarg(
396+
c, "verbose", CLI_CMD_OPTIONAL_FLAG | CLI_CMD_OPTION_MULTIPLE, PRIVILEGE_UNPRIVILEGED, MODE_EXEC,
397+
"Set verbose flag with some humongously long string \nwithout any embedded newlines in it to test with", NULL,
398+
NULL, NULL);
376399
o = cli_register_optarg(c, "color", CLI_CMD_OPTIONAL_ARGUMENT, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Set color",
377-
color_completor, color_validator, NULL);
378-
cli_optarg_addhelp(o, "black" , "the color 'black'");
379-
cli_optarg_addhelp(o, "white" , "the color 'white'");
380-
cli_optarg_addhelp(o, "gray" , "the color 'gray'");
381-
cli_optarg_addhelp(o, "red" , "the color 'red'");
382-
cli_optarg_addhelp(o, "blue" , "the color 'blue'");
383-
cli_optarg_addhelp(o, "green" , "the color 'green'");
384-
cli_optarg_addhelp(o, "lightred" , "the color 'lightred'");
385-
cli_optarg_addhelp(o, "lightblue" , "the color 'lightblue'");
386-
cli_optarg_addhelp(o, "lightgreen" , "the color 'lightgreen'");
387-
cli_optarg_addhelp(o, "darkred" , "the color 'darkred'");
388-
cli_optarg_addhelp(o, "darkblue" , "the color 'darkblue'");
389-
cli_optarg_addhelp(o, "darkgreen" , "the color 'darkgreen'");
390-
cli_optarg_addhelp(o, "lavender" , "the color 'lavender'");
391-
cli_optarg_addhelp(o, "yellow" , "the color 'yellow'");
392-
400+
color_completor, color_validator, NULL);
401+
cli_optarg_addhelp(o, "black", "the color 'black'");
402+
cli_optarg_addhelp(o, "white", "the color 'white'");
403+
cli_optarg_addhelp(o, "gray", "the color 'gray'");
404+
cli_optarg_addhelp(o, "red", "the color 'red'");
405+
cli_optarg_addhelp(o, "blue", "the color 'blue'");
406+
cli_optarg_addhelp(o, "green", "the color 'green'");
407+
cli_optarg_addhelp(o, "lightred", "the color 'lightred'");
408+
cli_optarg_addhelp(o, "lightblue", "the color 'lightblue'");
409+
cli_optarg_addhelp(o, "lightgreen", "the color 'lightgreen'");
410+
cli_optarg_addhelp(o, "darkred", "the color 'darkred'");
411+
cli_optarg_addhelp(o, "darkblue", "the color 'darkblue'");
412+
cli_optarg_addhelp(o, "darkgreen", "the color 'darkgreen'");
413+
cli_optarg_addhelp(o, "lavender", "the color 'lavender'");
414+
cli_optarg_addhelp(o, "yellow", "the color 'yellow'");
415+
393416
cli_register_optarg(c, "__check1__", CLI_CMD_SPOT_CHECK, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL, NULL,
394417
check1_validator, NULL);
395418
o = cli_register_optarg(c, "shape", CLI_CMD_ARGUMENT | CLI_CMD_ALLOW_BUILDMODE, PRIVILEGE_UNPRIVILEGED, MODE_EXEC,
396-
"Specify shape(shows subtext on help)", shape_completor, shape_validator, shape_transient_eval);
419+
"Specify shape(shows subtext on help)", shape_completor, shape_validator,
420+
shape_transient_eval);
397421
cli_optarg_addhelp(o, "triangle", "specify a triangle");
398422
cli_optarg_addhelp(o, "rectangle", "specify a rectangle");
399423

@@ -412,6 +436,13 @@ void run_child(int x) {
412436
cli_register_optarg(c, "side_4", CLI_CMD_ARGUMENT, PRIVILEGE_UNPRIVILEGED, MODE_POLYGON_RECTANGLE,
413437
"Specify side 4 length", NULL, side_length_validator, NULL);
414438

439+
c = cli_register_command(cli, NULL, "string", cmd_string, PRIVILEGE_UNPRIVILEGED, MODE_EXEC,
440+
"string input argument testing");
441+
442+
cli_register_optarg(c, "buildmode", CLI_CMD_OPTIONAL_FLAG | CLI_CMD_ALLOW_BUILDMODE, PRIVILEGE_UNPRIVILEGED,
443+
MODE_EXEC, "flag", NULL, NULL, NULL);
444+
cli_register_optarg(c, "text", CLI_CMD_ARGUMENT, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "text string", NULL, NULL, NULL);
445+
415446
// Set user context and its command
416447
cli_set_context(cli, (void *)&myctx);
417448
cli_register_command(cli, NULL, "context", cmd_context, PRIVILEGE_UNPRIVILEGED, MODE_EXEC,

0 commit comments

Comments
 (0)