Differences From
Artifact [91db6a8cad]:
21 21 * `size_t optc` - the number of options in the list to process.
22 22
23 23 a kcli_set might be used like so:
24 24
25 25 #include <k/core.h>
26 26 #include <k/io.h>
27 27 #include <k/cli.h>
28 - u8 entry(kenv e) {
28 + stat entry(kenv e) {
29 29 kcli_flag aardvark;
30 30 kcli_flag zebra;
31 31 char* user;
32 32 char* password;
33 33 long age;
34 - kcli_param* params = {
34 + kcli_param params[] = {
35 35 { "user", kcli_param_string, kcli_class_required,
36 36 &user, "the user to log in as" }
37 37 // or Kcli_param(user,string,required,"the user to log in as"),
38 38
39 39 { "age", kcli_param_dec, kcli_class_optional,
40 40 &age, "the age of the user" }
41 41 // or Kcli_param(age,dec,optional,"the age of the user"),
42 42 };
43 - kcli_opt* options = {
43 + kcli_opt options[] = {
44 44 { 'a', "aardvark", kcli_opt_flag, &aardvark,
45 45 "a nocturnal burrowing mammal" },
46 46 // or Kcli_opt(aardvark, 'a', flag, "a nocturnal burrowing mammal")
47 47 { 'z', "zebra", kcli_opt_flag, &zebra,
48 48 "a striped equine" },
49 49 { 'p', "password", kcli_opt_string, &password,
50 50 "the password to log in with" }
51 51 };
52 - kcli_set me = {
52 + kcli_set argset = {
53 53 "demo", e.argc, e.argv,
54 54 "a demonstration of the kcli_set type",
55 55 params, Kmsz(params),
56 56 options, Kmsz(options)
57 57 },
58 - size_t args_parsed = kcli_parse(&me);
58 + size_t args_parsed = kcli_parse(&argset);
59 59 if (args_parsed == 0) { kcli_usage(&me, e.err); return 1; }
60 60
61 61 return 0;
62 62 }
63 63
64 64 ### struct kcli_opt
65 65 a `kcli_opt` is a representation of a command-line flag and its function. each option must have a unique `id` and/or a unique `name`.
................................................................................
76 76 * `kcli_opt_string` - flag tells kcli to add a string to the list of expected parameters; appropriate string will be returned
77 77 * `kcli_opt_oct` - flag tells kcli to add an octal number to the list of expected parameters
78 78 * `kcli_opt_dec` - flag tells kcli to add a decimal number to the list of expected parameters
79 79 * `kcli_opt_hex` - flag tells kcli to add a hexdecimal number to the list of expected parameters
80 80 * `kcli_opt_flag` - flag is an option: will return `kcli_flag_on` if entered at least once, `kcli_flag_off` otherwise.
81 81 * `kcli_opt_toggle` - flag toggles value on and off: will return `kcli_flag_on` if entered an odd number of times, `kcli_flag_off` otherwise.
82 82 * `kcli_opt_accumulate` - flag increments a value every time it is entered; often used to implement `-v (--verbose)`-style options (e.g. `-vvvv` would return a value of `4`).
83 + * `kcli_opt_enum` - flag is one of a series of enumerated values, which will be matched against a table to yield the associated integer.
83 84
84 85 ### struct kcli_param
85 86 `kcli_param` describes a parameter that may be passed to the program whether or not any flags are passed.
86 87
87 88 * `const char* name` - a short name for the parameter
88 89 * `kcli_param_kind kind` - the kind of parameter passed
89 90 * `kcli_class class` - whether or not the parameter is optional