2017-06-13 09:40:58 +08:00
|
|
|
// Implementation of the emit builtin.
|
|
|
|
#include "config.h" // IWYU pragma: keep
|
|
|
|
|
2021-11-10 09:07:15 +08:00
|
|
|
#include "emit.h"
|
2019-10-14 06:50:48 +08:00
|
|
|
|
2021-11-10 09:07:15 +08:00
|
|
|
#include "../builtin.h"
|
|
|
|
#include "../common.h"
|
|
|
|
#include "../event.h"
|
|
|
|
#include "../fallback.h" // IWYU pragma: keep
|
|
|
|
#include "../io.h"
|
|
|
|
#include "../wutil.h" // IWYU pragma: keep
|
2017-06-13 09:40:58 +08:00
|
|
|
|
|
|
|
/// Implementation of the builtin emit command, used to create events.
|
2021-02-14 10:41:09 +08:00
|
|
|
maybe_t<int> builtin_emit(parser_t &parser, io_streams_t &streams, const wchar_t **argv) {
|
2017-06-13 09:40:58 +08:00
|
|
|
const wchar_t *cmd = argv[0];
|
|
|
|
int argc = builtin_count_args(argv);
|
2017-06-17 11:42:33 +08:00
|
|
|
help_only_cmd_opts_t opts;
|
2017-06-13 09:40:58 +08:00
|
|
|
|
|
|
|
int optind;
|
2017-06-17 11:42:33 +08:00
|
|
|
int retval = parse_help_only_cmd_opts(opts, &optind, argc, argv, parser, streams);
|
2017-06-13 09:40:58 +08:00
|
|
|
if (retval != STATUS_CMD_OK) return retval;
|
|
|
|
|
|
|
|
if (opts.print_help) {
|
2019-10-20 17:38:17 +08:00
|
|
|
builtin_print_help(parser, streams, cmd);
|
2017-06-15 03:26:05 +08:00
|
|
|
return STATUS_CMD_OK;
|
2017-06-13 09:40:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!argv[optind]) {
|
2017-06-17 11:42:33 +08:00
|
|
|
streams.err.append_format(L"%ls: expected event name\n", cmd);
|
|
|
|
return STATUS_INVALID_ARGS;
|
2017-06-13 09:40:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const wchar_t *eventname = argv[optind];
|
|
|
|
wcstring_list_t args(argv + optind + 1, argv + argc);
|
2019-06-03 17:31:13 +08:00
|
|
|
event_fire_generic(parser, eventname, &args);
|
2017-06-13 09:40:58 +08:00
|
|
|
return STATUS_CMD_OK;
|
|
|
|
}
|