Clean up status_builtin options and enums

Drop usage of magic numbers and sort lists where possible.
This commit is contained in:
Mahmoud Al-Qudsi 2018-10-09 22:07:30 -05:00
parent 236556ba05
commit c6230ddfde

View File

@ -18,21 +18,21 @@
#include "wutil.h" // IWYU pragma: keep
enum status_cmd_t {
STATUS_IS_LOGIN = 1,
STATUS_IS_INTERACTIVE,
STATUS_CURRENT_CMD = 1,
STATUS_FEATURES,
STATUS_FILENAME,
STATUS_FUNCTION,
STATUS_IS_BLOCK,
STATUS_IS_BREAKPOINT,
STATUS_IS_COMMAND_SUB,
STATUS_IS_FULL_JOB_CTRL,
STATUS_IS_INTERACTIVE,
STATUS_IS_INTERACTIVE_JOB_CTRL,
STATUS_IS_LOGIN,
STATUS_IS_NO_JOB_CTRL,
STATUS_CURRENT_CMD,
STATUS_FILENAME,
STATUS_FUNCTION,
STATUS_LINE_NUMBER,
STATUS_SET_JOB_CONTROL,
STATUS_STACK_TRACE,
STATUS_FEATURES,
STATUS_TEST_FEATURE,
STATUS_UNDEF
};
@ -100,20 +100,20 @@ struct status_cmd_opts_t {
/// scripts.
static const wchar_t *const short_options = L":L:cbilfnhj:t";
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
{L"is-command-substitution", no_argument, NULL, 'c'},
{L"is-block", no_argument, NULL, 'b'},
{L"is-interactive", no_argument, NULL, 'i'},
{L"is-login", no_argument, NULL, 'l'},
{L"is-full-job-control", no_argument, NULL, 1},
{L"is-interactive-job-control", no_argument, NULL, 2},
{L"is-no-job-control", no_argument, NULL, 3},
{L"filename", no_argument, NULL, 'f'},
{L"current-filename", no_argument, NULL, 'f'},
{L"current-line-number", no_argument, NULL, 'n'},
{L"filename", no_argument, NULL, 'f'},
{L"is-block", no_argument, NULL, 'b'},
{L"is-command-substitution", no_argument, NULL, 'c'},
{L"is-full-job-control", no_argument, NULL, STATUS_IS_FULL_JOB_CTRL},
{L"is-interactive", no_argument, NULL, 'i'},
{L"is-interactive-job-control", no_argument, NULL, STATUS_IS_INTERACTIVE_JOB_CTRL},
{L"is-login", no_argument, NULL, 'l'},
{L"is-no-job-control", no_argument, NULL, STATUS_IS_NO_JOB_CTRL},
{L"job-control", required_argument, NULL, 'j'},
{L"level", required_argument, NULL, 'L'},
{L"line", no_argument, NULL, 'n'},
{L"line-number", no_argument, NULL, 'n'},
{L"current-line-number", no_argument, NULL, 'n'},
{L"job-control", required_argument, NULL, 'j'},
{L"print-stack-trace", no_argument, NULL, 't'},
{NULL, 0, NULL, 0}};
@ -151,19 +151,19 @@ static int parse_cmd_opts(status_cmd_opts_t &opts, int *optind, //!OCLINT(high
wgetopter_t w;
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
switch (opt) {
case 1: {
case STATUS_IS_FULL_JOB_CTRL: {
if (!set_status_cmd(cmd, opts, STATUS_IS_FULL_JOB_CTRL, streams)) {
return STATUS_CMD_ERROR;
}
break;
}
case 2: {
case STATUS_IS_INTERACTIVE_JOB_CTRL: {
if (!set_status_cmd(cmd, opts, STATUS_IS_INTERACTIVE_JOB_CTRL, streams)) {
return STATUS_CMD_ERROR;
}
break;
}
case 3: {
case STATUS_IS_NO_JOB_CTRL: {
if (!set_status_cmd(cmd, opts, STATUS_IS_NO_JOB_CTRL, streams)) {
return STATUS_CMD_ERROR;
}