Skip to content

Improve formatting #101

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions cli.c
Original file line number Diff line number Diff line change
@@ -64,14 +64,14 @@ static void print_usage(const char *argv0) {
static void print_version(void) { puts(VERSION); }

enum {
CLI_OPT_SOCKET_GROUP = CHAR_MAX + 1,
CLI_OPT_VMNET_MODE,
CLI_OPT_VMNET_INTERFACE,
CLI_OPT_VMNET_GATEWAY,
CLI_OPT_VMNET_DHCP_END,
CLI_OPT_VMNET_MASK,
CLI_OPT_VMNET_INTERFACE_ID,
CLI_OPT_VMNET_NAT66_PREFIX,
CLI_OPT_SOCKET_GROUP = CHAR_MAX + 1,
CLI_OPT_VMNET_MODE,
CLI_OPT_VMNET_INTERFACE,
CLI_OPT_VMNET_GATEWAY,
CLI_OPT_VMNET_DHCP_END,
CLI_OPT_VMNET_MASK,
CLI_OPT_VMNET_INTERFACE_ID,
CLI_OPT_VMNET_NAT66_PREFIX,
};

struct cli_options *cli_options_parse(int argc, char *argv[]) {
@@ -82,22 +82,18 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
}

const struct option longopts[] = {
{"socket-group", required_argument, NULL, CLI_OPT_SOCKET_GROUP},
{"vmnet-mode", required_argument, NULL, CLI_OPT_VMNET_MODE},
{"vmnet-interface", required_argument, NULL,
CLI_OPT_VMNET_INTERFACE},
{"vmnet-gateway", required_argument, NULL, CLI_OPT_VMNET_GATEWAY},
{"vmnet-dhcp-end", required_argument, NULL,
CLI_OPT_VMNET_DHCP_END},
{"vmnet-mask", required_argument, NULL, CLI_OPT_VMNET_MASK},
{"vmnet-interface-id", required_argument, NULL,
CLI_OPT_VMNET_INTERFACE_ID},
{"vmnet-nat66-prefix", required_argument, NULL,
CLI_OPT_VMNET_NAT66_PREFIX},
{"pidfile", required_argument, NULL, 'p'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
{0, 0, 0, 0},
{"socket-group", required_argument, NULL, CLI_OPT_SOCKET_GROUP},
{"vmnet-mode", required_argument, NULL, CLI_OPT_VMNET_MODE},
{"vmnet-interface", required_argument, NULL, CLI_OPT_VMNET_INTERFACE},
{"vmnet-gateway", required_argument, NULL, CLI_OPT_VMNET_GATEWAY},
{"vmnet-dhcp-end", required_argument, NULL, CLI_OPT_VMNET_DHCP_END},
{"vmnet-mask", required_argument, NULL, CLI_OPT_VMNET_MASK},
{"vmnet-interface-id", required_argument, NULL, CLI_OPT_VMNET_INTERFACE_ID},
{"vmnet-nat66-prefix", required_argument, NULL, CLI_OPT_VMNET_NAT66_PREFIX},
{"pidfile", required_argument, NULL, 'p'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
{0, 0, 0, 0},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use clang-format or something for maintaining the format.

Does clang-format or something support keeping this whitespacing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea but even if not having automatic formatting is better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the default styles (LLVM, GNU, Google, Chromium, Microsoft, Mozilla, WebKit) destroy the nice table. Maybe there is an option to align tables, or to disable formatting of part of a file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested it, but according to Disabling Formatting on a Piece of Code you can disable it for a block like this:

// clang-format off
  const struct option longopts[] = {
    {"socket-group",        required_argument,  NULL,   CLI_OPT_SOCKET_GROUP},
    {"vmnet-mode",          required_argument,  NULL,   CLI_OPT_VMNET_MODE},
    {"vmnet-interface",     required_argument,  NULL,   CLI_OPT_VMNET_INTERFACE},
    {"vmnet-gateway",       required_argument,  NULL,   CLI_OPT_VMNET_GATEWAY},
    {"vmnet-dhcp-end",      required_argument,  NULL,   CLI_OPT_VMNET_DHCP_END},
    {"vmnet-mask",          required_argument,  NULL,   CLI_OPT_VMNET_MASK},
    {"vmnet-interface-id",  required_argument,  NULL,   CLI_OPT_VMNET_INTERFACE_ID},
    {"vmnet-nat66-prefix",  required_argument,  NULL,   CLI_OPT_VMNET_NAT66_PREFIX},
    {"pidfile",             required_argument,  NULL,   'p'},
    {"help",                no_argument,        NULL,   'h'},
    {"version",             no_argument,        NULL,   'v'},
    {0, 0, 0, 0},
  };
// clang-format on

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #104

};
int opt = 0;
while ((opt = getopt_long(argc, argv, "hvp:", longopts, NULL)) != -1) {