Skip to content
This repository was archived by the owner on May 4, 2024. It is now read-only.

Commit 7d42f83

Browse files
committed
cli.c: minor refactoring
Signed-off-by: Akihiro Suda <[email protected]>
1 parent 52dcaa3 commit 7d42f83

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

cli.c

+12-3
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
#error "Requires macOS 10.15 or later"
1717
#endif
1818

19+
#define CLI_DEFAULT_VDE_GROUP "staff"
20+
1921
static void print_usage(const char *argv0) {
2022
printf("Usage: %s [OPTION]... VDESWITCH\n", argv0);
2123
printf("vmnet.framework support for rootless QEMU.\n");
2224
printf("vde_vmnet does not require QEMU to run as the root user, but "
2325
"vde_vmnet itself has to run as the root, in most cases.\n");
2426
printf("\n");
2527
printf("--vde-group=GROUP VDE group name (default: "
26-
"\"staff\")\n");
28+
"\"" CLI_DEFAULT_VDE_GROUP "\")\n");
2729
printf(
2830
"--vmnet-mode=(host|shared|bridged) vmnet mode (default: \"shared\")\n");
2931
printf("--vmnet-interface=INTERFACE interface used for "
@@ -46,8 +48,6 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
4648
goto error;
4749
}
4850
memset(res, 0, sizeof(*res));
49-
res->vde_group = strdup("staff"); /* use strdup to make it freeable */
50-
res->vmnet_mode = VMNET_SHARED_MODE;
5151

5252
const struct option longopts[] = {
5353
{"vde-group", required_argument, NULL, CLI_OPTIONS_ID_VDE_GROUP},
@@ -100,6 +100,15 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
100100
goto error;
101101
}
102102
res->vde_switch = strdup(argv[optind]);
103+
104+
/* fill default */
105+
if (res->vde_group == NULL)
106+
res->vde_group =
107+
strdup(CLI_DEFAULT_VDE_GROUP); /* use strdup to make it freeable */
108+
if (res->vmnet_mode == 0)
109+
res->vmnet_mode = VMNET_SHARED_MODE;
110+
111+
/* validate */
103112
if (res->vmnet_mode == VMNET_BRIDGED_MODE && res->vmnet_interface == NULL) {
104113
fprintf(
105114
stderr,

0 commit comments

Comments
 (0)