change help only cmd opts interface

This commit is contained in:
Kurtis Rader 2017-06-16 20:42:33 -07:00
parent 37b8cfaeba
commit d22743dad0
11 changed files with 34 additions and 31 deletions

View file

@ -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) {

View file

@ -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

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -14,17 +14,17 @@
#include "io.h"
#include "proc.h"
#include "reader.h"
#include "tokenizer.h" // for tok_first
#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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -3,8 +3,8 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h> // for NULL, close, dup
#include <wchar.h> // for wcscmp
#include <unistd.h>
#include <wchar.h>
#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) {