mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-20 18:41:16 -03:00
split builtin bg into its own module
This commit is contained in:
@@ -15,50 +15,16 @@
|
||||
#include "proc.h"
|
||||
#include "reader.h"
|
||||
#include "tokenizer.h" // for tok_first
|
||||
#include "wgetopt.h"
|
||||
#include "wutil.h" // IWYU pragma: keep
|
||||
|
||||
struct cmd_opts {
|
||||
bool print_help = false;
|
||||
};
|
||||
static const wchar_t *short_options = L"h";
|
||||
static const struct woption long_options[] = {{L"help", no_argument, NULL, 'h'},
|
||||
{NULL, 0, NULL, 0}};
|
||||
|
||||
static int parse_cmd_opts(struct cmd_opts *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;
|
||||
return STATUS_CMD_OK;
|
||||
}
|
||||
case '?': {
|
||||
builtin_unknown_option(parser, streams, cmd, argv[w.woptind - 1]);
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
default: {
|
||||
DIE("unexpected retval from wgetopt_long");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*optind = w.woptind;
|
||||
return STATUS_CMD_OK;
|
||||
}
|
||||
|
||||
/// 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 opts;
|
||||
struct cmd_opts_help_only opts;
|
||||
|
||||
int optind;
|
||||
int retval = parse_cmd_opts(&opts, &optind, argc, argv, parser, streams);
|
||||
int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams);
|
||||
if (retval != STATUS_CMD_OK) return retval;
|
||||
|
||||
if (opts.print_help) {
|
||||
|
||||
Reference in New Issue
Block a user