From d22743dad0d6c5cb64895e6d790aa46b1726a9ad Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Fri, 16 Jun 2017 20:42:33 -0700 Subject: [PATCH] change help only cmd opts interface --- src/builtin.cpp | 10 +++++----- src/builtin.h | 4 ++-- src/builtin_bg.cpp | 4 ++-- src/builtin_cd.cpp | 5 +++-- src/builtin_disown.cpp | 4 ++-- src/builtin_emit.cpp | 8 ++++---- src/builtin_fg.cpp | 8 ++++---- src/builtin_pwd.cpp | 5 +++-- src/builtin_random.cpp | 4 ++-- src/builtin_realpath.cpp | 4 ++-- src/builtin_source.cpp | 9 +++++---- 11 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/builtin.cpp b/src/builtin.cpp index 3072c21ab..7fd8a69f9 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -110,15 +110,15 @@ static const wchar_t *short_options = L"h"; static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0}}; -int parse_cmd_opts_help_only(struct cmd_opts_help_only *opts, int *optind, int argc, wchar_t **argv, - parser_t &parser, io_streams_t &streams) { +int parse_help_only_cmd_opts(struct help_only_cmd_opts_t &opts, int *optind, int argc, + wchar_t **argv, parser_t &parser, io_streams_t &streams) { wchar_t *cmd = argv[0]; int opt; wgetopter_t w; while ((opt = w.wgetopt_long(argc, argv, short_options, long_options, NULL)) != -1) { switch (opt) { //!OCLINT(too few branches) case 'h': { - opts->print_help = true; + opts.print_help = true; break; } case '?': { @@ -278,9 +278,9 @@ void builtin_missing_argument(parser_t &parser, io_streams_t &streams, const wch static int builtin_generic(parser_t &parser, io_streams_t &streams, wchar_t **argv) { const wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); - struct cmd_opts_help_only opts; + help_only_cmd_opts_t opts; int optind; - int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams); + int retval = parse_help_only_cmd_opts(opts, &optind, argc, argv, parser, streams); if (retval != STATUS_CMD_OK) return retval; if (opts.print_help) { diff --git a/src/builtin.h b/src/builtin.h index 364478d29..cf7c29ffa 100644 --- a/src/builtin.h +++ b/src/builtin.h @@ -114,9 +114,9 @@ void builtin_missing_argument(parser_t &parser, io_streams_t &streams, const wch void builtin_wperror(const wchar_t *s, io_streams_t &streams); -struct cmd_opts_help_only { +struct help_only_cmd_opts_t { bool print_help = false; }; -int parse_cmd_opts_help_only(struct cmd_opts_help_only *opts, int *optind, int argc, wchar_t **argv, +int parse_help_only_cmd_opts(help_only_cmd_opts_t &opts, int *optind, int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams); #endif diff --git a/src/builtin_bg.cpp b/src/builtin_bg.cpp index 1b63e8d9e..076e57f20 100644 --- a/src/builtin_bg.cpp +++ b/src/builtin_bg.cpp @@ -38,10 +38,10 @@ static int send_to_bg(parser_t &parser, io_streams_t &streams, job_t *j) { int builtin_bg(parser_t &parser, io_streams_t &streams, wchar_t **argv) { const wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); - cmd_opts_help_only opts; + help_only_cmd_opts_t opts; int optind; - int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams); + int retval = parse_help_only_cmd_opts(opts, &optind, argc, argv, parser, streams); if (retval != STATUS_CMD_OK) return retval; if (opts.print_help) { diff --git a/src/builtin_cd.cpp b/src/builtin_cd.cpp index 927b7a7d3..e73808fab 100644 --- a/src/builtin_cd.cpp +++ b/src/builtin_cd.cpp @@ -22,9 +22,10 @@ int builtin_cd(parser_t &parser, io_streams_t &streams, wchar_t **argv) { const wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); - struct cmd_opts_help_only opts; + help_only_cmd_opts_t opts; + int optind; - int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams); + int retval = parse_help_only_cmd_opts(opts, &optind, argc, argv, parser, streams); if (retval != STATUS_CMD_OK) return retval; if (opts.print_help) { diff --git a/src/builtin_disown.cpp b/src/builtin_disown.cpp index 1a0c608d7..7a26e6f2d 100644 --- a/src/builtin_disown.cpp +++ b/src/builtin_disown.cpp @@ -39,10 +39,10 @@ static int disown_job(const wchar_t *cmd, parser_t &parser, io_streams_t &stream int builtin_disown(parser_t &parser, io_streams_t &streams, wchar_t **argv) { const wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); - struct cmd_opts_help_only opts; + help_only_cmd_opts_t opts; int optind; - int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams); + int retval = parse_help_only_cmd_opts(opts, &optind, argc, argv, parser, streams); if (retval != STATUS_CMD_OK) return retval; if (opts.print_help) { diff --git a/src/builtin_emit.cpp b/src/builtin_emit.cpp index 1c861123e..805984816 100644 --- a/src/builtin_emit.cpp +++ b/src/builtin_emit.cpp @@ -13,10 +13,10 @@ int builtin_emit(parser_t &parser, io_streams_t &streams, wchar_t **argv) { const wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); - struct cmd_opts_help_only opts; + help_only_cmd_opts_t opts; int optind; - int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams); + int retval = parse_help_only_cmd_opts(opts, &optind, argc, argv, parser, streams); if (retval != STATUS_CMD_OK) return retval; if (opts.print_help) { @@ -25,8 +25,8 @@ int builtin_emit(parser_t &parser, io_streams_t &streams, wchar_t **argv) { } if (!argv[optind]) { - streams.err.append_format(L"%ls: expected event name\n", cmd); - return STATUS_INVALID_ARGS; + streams.err.append_format(L"%ls: expected event name\n", cmd); + return STATUS_INVALID_ARGS; } const wchar_t *eventname = argv[optind]; diff --git a/src/builtin_fg.cpp b/src/builtin_fg.cpp index 5d565c541..b4b32e4d7 100644 --- a/src/builtin_fg.cpp +++ b/src/builtin_fg.cpp @@ -14,17 +14,17 @@ #include "io.h" #include "proc.h" #include "reader.h" -#include "tokenizer.h" // for tok_first -#include "wutil.h" // IWYU pragma: keep +#include "tokenizer.h" +#include "wutil.h" // IWYU pragma: keep /// Builtin for putting a job in the foreground. int builtin_fg(parser_t &parser, io_streams_t &streams, wchar_t **argv) { const wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); - struct cmd_opts_help_only opts; + help_only_cmd_opts_t opts; int optind; - int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams); + int retval = parse_help_only_cmd_opts(opts, &optind, argc, argv, parser, streams); if (retval != STATUS_CMD_OK) return retval; if (opts.print_help) { diff --git a/src/builtin_pwd.cpp b/src/builtin_pwd.cpp index c700ab6a0..79cea74e5 100644 --- a/src/builtin_pwd.cpp +++ b/src/builtin_pwd.cpp @@ -14,9 +14,10 @@ int builtin_pwd(parser_t &parser, io_streams_t &streams, wchar_t **argv) { UNUSED(parser); const wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); - struct cmd_opts_help_only opts; + help_only_cmd_opts_t opts; + int optind; - int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams); + int retval = parse_help_only_cmd_opts(opts, &optind, argc, argv, parser, streams); if (retval != STATUS_CMD_OK) return retval; if (opts.print_help) { diff --git a/src/builtin_random.cpp b/src/builtin_random.cpp index 3270ab38b..c8bbc7a1f 100644 --- a/src/builtin_random.cpp +++ b/src/builtin_random.cpp @@ -19,10 +19,10 @@ int builtin_random(parser_t &parser, io_streams_t &streams, wchar_t **argv) { wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); - struct cmd_opts_help_only opts; + help_only_cmd_opts_t opts; int optind; - int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams); + int retval = parse_help_only_cmd_opts(opts, &optind, argc, argv, parser, streams); if (retval != STATUS_CMD_OK) return retval; if (opts.print_help) { diff --git a/src/builtin_realpath.cpp b/src/builtin_realpath.cpp index 34e6dc521..5da3ef7ef 100644 --- a/src/builtin_realpath.cpp +++ b/src/builtin_realpath.cpp @@ -20,10 +20,10 @@ int builtin_realpath(parser_t &parser, io_streams_t &streams, wchar_t **argv) { const wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); - struct cmd_opts_help_only opts; + help_only_cmd_opts_t opts; int optind; - int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams); + int retval = parse_help_only_cmd_opts(opts, &optind, argc, argv, parser, streams); if (retval != STATUS_CMD_OK) return retval; if (opts.print_help) { diff --git a/src/builtin_source.cpp b/src/builtin_source.cpp index ce2e51e7f..e33a4a188 100644 --- a/src/builtin_source.cpp +++ b/src/builtin_source.cpp @@ -3,8 +3,8 @@ #include #include -#include // for NULL, close, dup -#include // for wcscmp +#include +#include #include "builtin.h" #include "builtin_source.h" @@ -24,9 +24,10 @@ int builtin_source(parser_t &parser, io_streams_t &streams, wchar_t **argv) { ASSERT_IS_MAIN_THREAD(); const wchar_t *cmd = argv[0]; int argc = builtin_count_args(argv); - struct cmd_opts_help_only opts; + help_only_cmd_opts_t opts; + int optind; - int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams); + int retval = parse_help_only_cmd_opts(opts, &optind, argc, argv, parser, streams); if (retval != STATUS_CMD_OK) return retval; if (opts.print_help) {