fish-shell/src/builtin_emit.cpp
Johannes Altmanninger 61486954bc Use a pager to view long outputs of builtin --help
Every builtin or function shipped with fish supports flag -h or --help to
print a slightly condensed version of its manpage.
Some of those help messages are longer than a typical screen;
this commit pipes the help to a pager to make it easier to read.

As in other places in fish we assume that either $PAGER or "less" is a
valid pager and use that.

In three places (error messages for bg, break and continue) the help is
printed to stderr instead of stdout.  To make sure the error message is
visible in the pager, we pass it to builtin_print_help, every call of which
needs to be updated.

Fixes #6227
2019-10-28 18:36:07 +01:00

37 lines
1.1 KiB
C++

// Implementation of the emit builtin.
#include "config.h" // IWYU pragma: keep
#include "builtin_emit.h"
#include "builtin.h"
#include "common.h"
#include "event.h"
#include "fallback.h" // IWYU pragma: keep
#include "io.h"
#include "wutil.h" // IWYU pragma: keep
/// Implementation of the builtin emit command, used to create events.
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);
help_only_cmd_opts_t opts;
int optind;
int retval = parse_help_only_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) {
builtin_print_help(parser, streams, cmd);
return STATUS_CMD_OK;
}
if (!argv[optind]) {
streams.err.append_format(L"%ls: expected event name\n", cmd);
return STATUS_INVALID_ARGS;
}
const wchar_t *eventname = argv[optind];
wcstring_list_t args(argv + optind + 1, argv + argc);
event_fire_generic(parser, eventname, &args);
return STATUS_CMD_OK;
}