Introduce special G_VAL_OPTIONAL define, which when given in value field
tells geom(8) to ignore it when it is not given and don't try to obtain default value.
This commit is contained in:
parent
4eeef2e44a
commit
7648b1e9c0
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=212606
@ -90,16 +90,16 @@ struct g_command PUBSYM(class_commands)[] = {
|
|||||||
{ 'b', "start", GPART_AUTOFILL, G_TYPE_STRING },
|
{ 'b', "start", GPART_AUTOFILL, G_TYPE_STRING },
|
||||||
{ 's', "size", GPART_AUTOFILL, G_TYPE_STRING },
|
{ 's', "size", GPART_AUTOFILL, G_TYPE_STRING },
|
||||||
{ 't', "type", NULL, G_TYPE_STRING },
|
{ 't', "type", NULL, G_TYPE_STRING },
|
||||||
{ 'i', GPART_PARAM_INDEX, "", G_TYPE_ASCNUM },
|
{ 'i', GPART_PARAM_INDEX, G_VAL_OPTIONAL, G_TYPE_ASCNUM },
|
||||||
{ 'l', "label", "", G_TYPE_STRING },
|
{ 'l', "label", G_VAL_OPTIONAL, G_TYPE_STRING },
|
||||||
{ 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
|
{ 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
|
||||||
G_OPT_SENTINEL },
|
G_OPT_SENTINEL },
|
||||||
"[-b start] [-s size] -t type [-i index] [-l label] [-f flags] geom"
|
"[-b start] [-s size] -t type [-i index] [-l label] [-f flags] geom"
|
||||||
},
|
},
|
||||||
{ "bootcode", 0, gpart_bootcode, {
|
{ "bootcode", 0, gpart_bootcode, {
|
||||||
{ 'b', GPART_PARAM_BOOTCODE, "", G_TYPE_STRING },
|
{ 'b', GPART_PARAM_BOOTCODE, G_VAL_OPTIONAL, G_TYPE_STRING },
|
||||||
{ 'p', GPART_PARAM_PARTCODE, "", G_TYPE_STRING },
|
{ 'p', GPART_PARAM_PARTCODE, G_VAL_OPTIONAL, G_TYPE_STRING },
|
||||||
{ 'i', GPART_PARAM_INDEX, "", G_TYPE_ASCNUM },
|
{ 'i', GPART_PARAM_INDEX, G_VAL_OPTIONAL, G_TYPE_ASCNUM },
|
||||||
{ 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
|
{ 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
|
||||||
G_OPT_SENTINEL },
|
G_OPT_SENTINEL },
|
||||||
"bootcode [-b bootcode] [-p partcode] [-i index] [-f flags] geom"
|
"bootcode [-b bootcode] [-p partcode] [-i index] [-f flags] geom"
|
||||||
@ -109,7 +109,7 @@ struct g_command PUBSYM(class_commands)[] = {
|
|||||||
},
|
},
|
||||||
{ "create", 0, gpart_issue, {
|
{ "create", 0, gpart_issue, {
|
||||||
{ 's', "scheme", NULL, G_TYPE_STRING },
|
{ 's', "scheme", NULL, G_TYPE_STRING },
|
||||||
{ 'n', "entries", "", G_TYPE_ASCNUM },
|
{ 'n', "entries", G_VAL_OPTIONAL, G_TYPE_ASCNUM },
|
||||||
{ 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
|
{ 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
|
||||||
G_OPT_SENTINEL },
|
G_OPT_SENTINEL },
|
||||||
"-s scheme [-n entries] [-f flags] provider"
|
"-s scheme [-n entries] [-f flags] provider"
|
||||||
@ -127,8 +127,8 @@ struct g_command PUBSYM(class_commands)[] = {
|
|||||||
},
|
},
|
||||||
{ "modify", 0, gpart_issue, {
|
{ "modify", 0, gpart_issue, {
|
||||||
{ 'i', GPART_PARAM_INDEX, NULL, G_TYPE_ASCNUM },
|
{ 'i', GPART_PARAM_INDEX, NULL, G_TYPE_ASCNUM },
|
||||||
{ 'l', "label", "", G_TYPE_STRING },
|
{ 'l', "label", G_VAL_OPTIONAL, G_TYPE_STRING },
|
||||||
{ 't', "type", "", G_TYPE_STRING },
|
{ 't', "type", G_VAL_OPTIONAL, G_TYPE_STRING },
|
||||||
{ 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
|
{ 'f', "flags", GPART_FLAGS, G_TYPE_STRING },
|
||||||
G_OPT_SENTINEL },
|
G_OPT_SENTINEL },
|
||||||
"-i index [-l label] [-t type] [-f flags] geom"
|
"-i index [-l label] [-t type] [-f flags] geom"
|
||||||
|
@ -374,9 +374,8 @@ parse_arguments(struct g_command *cmd, struct gctl_req *req, int *argc,
|
|||||||
warnx("Option '%c' not specified.",
|
warnx("Option '%c' not specified.",
|
||||||
opt->go_char);
|
opt->go_char);
|
||||||
usage();
|
usage();
|
||||||
} else if (G_OPT_TYPE(opt) == G_TYPE_ASCNUM &&
|
} else if (opt->go_val == G_VAL_OPTIONAL) {
|
||||||
*(const char *)opt->go_val == '\0') {
|
/* add nothing. */
|
||||||
; /* add nothing. */
|
|
||||||
} else {
|
} else {
|
||||||
set_option(req, opt, opt->go_val);
|
set_option(req, opt, opt->go_val);
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,8 @@
|
|||||||
#define G_OPT_NUM(opt) (((opt)->go_type & G_TYPE_NUMMASK) >> G_TYPE_NUMSHIFT)
|
#define G_OPT_NUM(opt) (((opt)->go_type & G_TYPE_NUMMASK) >> G_TYPE_NUMSHIFT)
|
||||||
#define G_OPT_NUMINC(opt) ((opt)->go_type += (1 << G_TYPE_NUMSHIFT))
|
#define G_OPT_NUMINC(opt) ((opt)->go_type += (1 << G_TYPE_NUMSHIFT))
|
||||||
|
|
||||||
|
#define G_VAL_OPTIONAL ((void *)-1)
|
||||||
|
|
||||||
#define G_OPT_SENTINEL { '\0', NULL, NULL, G_TYPE_NONE }
|
#define G_OPT_SENTINEL { '\0', NULL, NULL, G_TYPE_NONE }
|
||||||
#define G_NULL_OPTS { G_OPT_SENTINEL }
|
#define G_NULL_OPTS { G_OPT_SENTINEL }
|
||||||
#define G_CMD_SENTINEL { NULL, 0, NULL, G_NULL_OPTS, NULL }
|
#define G_CMD_SENTINEL { NULL, 0, NULL, G_NULL_OPTS, NULL }
|
||||||
|
Loading…
Reference in New Issue
Block a user