change naming convention for parsing opts

This commit is contained in:
Kurtis Rader 2017-06-13 13:03:32 -07:00
parent 044f5512e2
commit 59e90123ea
8 changed files with 45 additions and 46 deletions

View file

@ -19,7 +19,7 @@
#include "wutil.h" // IWYU pragma: keep #include "wutil.h" // IWYU pragma: keep
enum { BIND_INSERT, BIND_ERASE, BIND_KEY_NAMES, BIND_FUNCTION_NAMES }; enum { BIND_INSERT, BIND_ERASE, BIND_KEY_NAMES, BIND_FUNCTION_NAMES };
struct bind_opts { struct cmd_opts {
int mode = BIND_INSERT; int mode = BIND_INSERT;
int res = STATUS_CMD_OK; int res = STATUS_CMD_OK;
bool all = false; bool all = false;
@ -212,7 +212,7 @@ static bool builtin_bind_erase(wchar_t **seq, int all, const wchar_t *mode, int
return res; return res;
} }
static bool builtin_bind_insert(struct bind_opts *opts, int optind, int argc, wchar_t **argv, static bool builtin_bind_insert(struct cmd_opts *opts, int optind, int argc, wchar_t **argv,
io_streams_t &streams) { io_streams_t &streams) {
wchar_t *cmd = argv[0]; wchar_t *cmd = argv[0];
int arg_count = argc - optind; int arg_count = argc - optind;
@ -267,7 +267,7 @@ static void builtin_bind_list_modes(io_streams_t &streams) {
} }
} }
static int parse_bind_opts(struct bind_opts *opts, int *optind, //!OCLINT(high ncss method) static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0]; wchar_t *cmd = argv[0];
static const wchar_t *short_options = L"aehkKfM:Lm:"; static const wchar_t *short_options = L"aehkKfM:Lm:";
@ -350,10 +350,10 @@ static int parse_bind_opts(struct bind_opts *opts, int *optind, //!OCLINT(high
int builtin_bind(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int builtin_bind(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
wchar_t *cmd = argv[0]; wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
struct bind_opts opts; struct cmd_opts opts;
int optind; int optind;
int retval = parse_bind_opts(&opts, &optind, argc, argv, parser, streams); int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval; if (retval != STATUS_CMD_OK) return retval;
if (opts.list_modes) { if (opts.list_modes) {

View file

@ -14,13 +14,13 @@
#include "wutil.h" // IWYU pragma: keep #include "wutil.h" // IWYU pragma: keep
enum { UNSET, GLOBAL, LOCAL }; enum { UNSET, GLOBAL, LOCAL };
struct block_opts { struct cmd_opts {
int scope = UNSET; int scope = UNSET;
bool erase = false; bool erase = false;
bool print_help = false; bool print_help = false;
}; };
static int parse_block_opts(struct block_opts *opts, int *optind, //!OCLINT(high ncss method) static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0]; wchar_t *cmd = argv[0];
static const wchar_t *short_options = L"eghl"; static const wchar_t *short_options = L"eghl";
@ -69,10 +69,10 @@ static int parse_block_opts(struct block_opts *opts, int *optind, //!OCLINT(hig
int builtin_block(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int builtin_block(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
const wchar_t *cmd = argv[0]; const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
struct block_opts opts; struct cmd_opts opts;
int optind; int optind;
int retval = parse_block_opts(&opts, &optind, argc, argv, parser, streams); int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval; if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) { if (opts.print_help) {

View file

@ -12,17 +12,16 @@
#include "wgetopt.h" #include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep #include "wutil.h" // IWYU pragma: keep
struct emit_opts { struct cmd_opts {
bool print_help = false; bool print_help = false;
}; };
static const wchar_t *short_options = L"h";
static int parse_emit_opts(struct emit_opts *opts, int *optind, //!OCLINT(high ncss method) static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0];
static const wchar_t *short_options = L"h";
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}}; {NULL, 0, NULL, 0}};
static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0];
int opt; int opt;
wgetopter_t w; wgetopter_t w;
while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
@ -50,10 +49,10 @@ static int parse_emit_opts(struct emit_opts *opts, int *optind, //!OCLINT(high
int builtin_emit(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int builtin_emit(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
const wchar_t *cmd = argv[0]; const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
struct emit_opts opts; struct cmd_opts opts;
int optind; int optind;
int retval = parse_emit_opts(&opts, &optind, argc, argv, parser, streams); int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval; if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) { if (opts.print_help) {

View file

@ -26,7 +26,7 @@
#include "wgetopt.h" #include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep #include "wutil.h" // IWYU pragma: keep
struct functions_opts { struct cmd_opts {
bool print_help = false; bool print_help = false;
bool erase = false; bool erase = false;
bool list = false; bool list = false;
@ -38,7 +38,7 @@ struct functions_opts {
wchar_t *description = NULL; wchar_t *description = NULL;
}; };
static int parse_functions_opts(struct functions_opts *opts, static int parse_cmd_opts(struct cmd_opts *opts,
int *optind, //!OCLINT(high ncss method) int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0]; wchar_t *cmd = argv[0];
@ -258,10 +258,10 @@ static int report_function_metadata(const wchar_t *funcname, bool verbose, io_st
int builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
const wchar_t *cmd = argv[0]; const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
struct functions_opts opts; struct cmd_opts opts;
int optind; int optind;
int retval = parse_functions_opts(&opts, &optind, argc, argv, parser, streams); int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval; if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) { if (opts.print_help) {

View file

@ -27,7 +27,7 @@ const enum_map<hist_cmd_t> hist_enum_map[] = {{HIST_CLEAR, L"clear"}, {HIST_DE
{HIST_SEARCH, L"search"}, {HIST_UNDEF, NULL}}; {HIST_SEARCH, L"search"}, {HIST_UNDEF, NULL}};
#define hist_enum_map_len (sizeof hist_enum_map / sizeof *hist_enum_map) #define hist_enum_map_len (sizeof hist_enum_map / sizeof *hist_enum_map)
struct history_opts { struct cmd_opts {
bool print_help = false; bool print_help = false;
hist_cmd_t hist_cmd = HIST_UNDEF; hist_cmd_t hist_cmd = HIST_UNDEF;
history_search_type_t search_type = (history_search_type_t)-1; history_search_type_t search_type = (history_search_type_t)-1;
@ -92,7 +92,7 @@ static bool set_hist_cmd(wchar_t *const cmd, hist_cmd_t *hist_cmd, hist_cmd_t su
break; \ break; \
} }
static int parse_history_opts(struct history_opts *opts, int *optind, //!OCLINT(high ncss method) static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0]; wchar_t *cmd = argv[0];
int opt; int opt;
@ -198,10 +198,10 @@ static int parse_history_opts(struct history_opts *opts, int *optind, //!OCLINT
int builtin_history(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int builtin_history(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
wchar_t *cmd = argv[0]; wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
struct history_opts opts; struct cmd_opts opts;
int optind; int optind;
int retval = parse_history_opts(&opts, &optind, argc, argv, parser, streams); int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval; if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) { if (opts.print_help) {

View file

@ -17,7 +17,7 @@
#include "wgetopt.h" #include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep #include "wutil.h" // IWYU pragma: keep
struct random_opts { struct cmd_opts {
bool print_help = false; bool print_help = false;
}; };
@ -25,7 +25,7 @@ static const wchar_t *short_options = L"h";
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'}, static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}}; {NULL, 0, NULL, 0}};
static int parse_random_opts(struct random_opts *opts, int *optind, //!OCLINT(high ncss method) static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0]; wchar_t *cmd = argv[0];
int opt; int opt;
@ -55,10 +55,10 @@ static int parse_random_opts(struct random_opts *opts, int *optind, //!OCLINT(h
int builtin_random(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int builtin_random(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
wchar_t *cmd = argv[0]; wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
struct random_opts opts; struct cmd_opts opts;
int optind; int optind;
int retval = parse_random_opts(&opts, &optind, argc, argv, parser, streams); int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval; if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) { if (opts.print_help) {

View file

@ -29,7 +29,7 @@
#include "wgetopt.h" #include "wgetopt.h"
#include "wutil.h" // IWYU pragma: keep #include "wutil.h" // IWYU pragma: keep
struct read_opts { struct cmd_opts {
bool print_help = false; bool print_help = false;
int place = ENV_USER; int place = ENV_USER;
wcstring prompt_cmd; wcstring prompt_cmd;
@ -64,7 +64,7 @@ static const struct woption long_options[] = {{L"export", no_argument, NULL, 'x'
{L"help", no_argument, NULL, 'h'}, {L"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}}; {NULL, 0, NULL, 0}};
static int parse_read_opts(struct read_opts *opts, int *optind, //!OCLINT(high ncss method) static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0]; wchar_t *cmd = argv[0];
int opt; int opt;
@ -321,10 +321,10 @@ int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
wcstring buff; wcstring buff;
int exit_res = STATUS_CMD_OK; int exit_res = STATUS_CMD_OK;
struct read_opts opts; struct cmd_opts opts;
int optind; int optind;
int retval = parse_read_opts(&opts, &optind, argc, argv, parser, streams); int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval; if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) { if (opts.print_help) {

View file

@ -70,7 +70,7 @@ int job_control_str_to_mode(const wchar_t *mode, wchar_t *cmd, io_streams_t &str
return -1; return -1;
} }
struct status_opts { struct cmd_opts {
bool print_help = false; bool print_help = false;
status_cmd_t status_cmd = STATUS_UNDEF; status_cmd_t status_cmd = STATUS_UNDEF;
int new_job_control_mode = -1; int new_job_control_mode = -1;
@ -113,7 +113,7 @@ static bool set_status_cmd(wchar_t *const cmd, status_cmd_t *status_cmd, status_
return true; return true;
} }
static int parse_status_opts(struct status_opts *opts, int *optind, //!OCLINT(high ncss method) static int parse_cmd_opts(struct cmd_opts *opts, int *optind, //!OCLINT(high ncss method)
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) { int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
wchar_t *cmd = argv[0]; wchar_t *cmd = argv[0];
int opt; int opt;
@ -218,10 +218,10 @@ static int parse_status_opts(struct status_opts *opts, int *optind, //!OCLINT(h
int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **argv) { int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
wchar_t *cmd = argv[0]; wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv); int argc = builtin_count_args(argv);
struct status_opts opts; struct cmd_opts opts;
int optind; int optind;
int retval = parse_status_opts(&opts, &optind, argc, argv, parser, streams); int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval; if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) { if (opts.print_help) {