2016-04-19 02:25:12 +00:00
|
|
|
// Prototypes for functions for executing builtin functions.
|
2005-10-04 15:11:39 +00:00
|
|
|
#ifndef FISH_BUILTIN_H
|
|
|
|
#define FISH_BUILTIN_H
|
|
|
|
|
2016-04-21 06:00:54 +00:00
|
|
|
#include <vector>
|
2005-10-04 15:11:39 +00:00
|
|
|
|
2012-01-16 16:56:47 +00:00
|
|
|
#include "common.h"
|
2022-08-21 06:14:48 +00:00
|
|
|
#include "complete.h"
|
|
|
|
#include "maybe.h"
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2012-01-16 20:10:08 +00:00
|
|
|
class parser_t;
|
2019-02-25 18:05:42 +00:00
|
|
|
class proc_status_t;
|
2016-04-21 06:00:54 +00:00
|
|
|
class output_stream_t;
|
|
|
|
struct io_streams_t;
|
2020-01-16 00:13:41 +00:00
|
|
|
using completion_list_t = std::vector<completion_t>;
|
2012-01-16 20:10:08 +00:00
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Data structure to describe a builtin.
|
|
|
|
struct builtin_data_t {
|
|
|
|
// Name of the builtin.
|
2018-09-29 04:22:24 +00:00
|
|
|
const wchar_t *name;
|
2019-10-22 00:21:40 +00:00
|
|
|
// Function pointer to the builtin implementation.
|
2021-02-14 02:41:09 +00:00
|
|
|
maybe_t<int> (*func)(parser_t &parser, io_streams_t &streams, const wchar_t **argv);
|
2016-08-16 22:30:49 +00:00
|
|
|
// Description of what the builtin does.
|
2018-09-29 04:22:24 +00:00
|
|
|
const wchar_t *desc;
|
2016-08-16 22:30:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// The default prompt for the read command.
|
|
|
|
#define DEFAULT_READ_PROMPT L"set_color green; echo -n read; set_color normal; echo -n \"> \""
|
|
|
|
|
|
|
|
/// Error message on missing argument.
|
2021-11-02 10:09:38 +00:00
|
|
|
#define BUILTIN_ERR_MISSING _(L"%ls: %ls: option requires an argument\n")
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2021-03-15 21:59:37 +00:00
|
|
|
/// Error message on missing man page.
|
2021-11-08 19:36:01 +00:00
|
|
|
#define BUILTIN_ERR_MISSING_HELP \
|
2021-11-02 10:09:38 +00:00
|
|
|
_(L"fish: %ls: missing man page\nDocumentation may not be installed.\n`help %ls` will " \
|
|
|
|
L"show an online version\n")
|
2021-03-15 21:59:37 +00:00
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Error message on invalid combination of options.
|
2021-11-02 10:09:38 +00:00
|
|
|
#define BUILTIN_ERR_COMBO _(L"%ls: invalid option combination\n")
|
2016-04-19 02:25:12 +00:00
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Error message on invalid combination of options.
|
2021-11-02 10:09:38 +00:00
|
|
|
#define BUILTIN_ERR_COMBO2 _(L"%ls: invalid option combination, %ls\n")
|
|
|
|
#define BUILTIN_ERR_COMBO2_EXCLUSIVE _(L"%ls: %ls %ls: options cannot be used together\n")
|
2016-04-19 02:25:12 +00:00
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Error message on multiple scope levels for variables.
|
2021-11-08 19:36:01 +00:00
|
|
|
#define BUILTIN_ERR_GLOCAL _(L"%ls: scope can be only one of: universal function global local\n")
|
2016-04-19 02:25:12 +00:00
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Error message for specifying both export and unexport to set/read.
|
2021-11-02 10:09:38 +00:00
|
|
|
#define BUILTIN_ERR_EXPUNEXP _(L"%ls: cannot both export and unexport\n")
|
2016-04-19 02:25:12 +00:00
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Error message for unknown switch.
|
2021-11-02 10:09:38 +00:00
|
|
|
#define BUILTIN_ERR_UNKNOWN _(L"%ls: %ls: unknown option\n")
|
2016-04-19 02:25:12 +00:00
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Error message for unexpected args.
|
2021-11-02 10:09:38 +00:00
|
|
|
#define BUILTIN_ERR_ARG_COUNT0 _(L"%ls: missing argument\n")
|
|
|
|
#define BUILTIN_ERR_ARG_COUNT1 _(L"%ls: expected %d arguments; got %d\n")
|
|
|
|
#define BUILTIN_ERR_ARG_COUNT2 _(L"%ls: %ls: expected %d arguments; got %d\n")
|
|
|
|
#define BUILTIN_ERR_MIN_ARG_COUNT1 _(L"%ls: expected >= %d arguments; got %d\n")
|
|
|
|
#define BUILTIN_ERR_MAX_ARG_COUNT1 _(L"%ls: expected <= %d arguments; got %d\n")
|
2016-07-14 05:33:50 +00:00
|
|
|
|
2017-04-20 06:43:02 +00:00
|
|
|
/// Error message for invalid variable name.
|
2022-04-08 14:36:06 +00:00
|
|
|
#define BUILTIN_ERR_VARNAME _(L"%ls: %ls: invalid variable name. See `help identifiers`\n")
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2017-04-23 03:33:56 +00:00
|
|
|
/// Error message for invalid bind mode name.
|
2022-04-08 14:36:06 +00:00
|
|
|
#define BUILTIN_ERR_BIND_MODE _(L"%ls: %ls: invalid mode name. See `help identifiers`\n")
|
2017-04-23 03:33:56 +00:00
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// Error message when too many arguments are supplied to a builtin.
|
2021-11-02 10:09:38 +00:00
|
|
|
#define BUILTIN_ERR_TOO_MANY_ARGUMENTS _(L"%ls: too many arguments\n")
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2019-09-18 05:00:08 +00:00
|
|
|
/// Error message when integer expected
|
2021-11-02 10:09:38 +00:00
|
|
|
#define BUILTIN_ERR_NOT_NUMBER _(L"%ls: %ls: invalid integer\n")
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2017-06-20 04:05:34 +00:00
|
|
|
/// Command that requires a subcommand was invoked without a recognized subcommand.
|
2021-11-02 10:09:38 +00:00
|
|
|
#define BUILTIN_ERR_MISSING_SUBCMD _(L"%ls: missing subcommand\n")
|
|
|
|
#define BUILTIN_ERR_INVALID_SUBCMD _(L"%ls: %ls: invalid subcommand\n")
|
2017-06-20 04:05:34 +00:00
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
/// The send stuff to foreground message.
|
2021-11-02 10:09:38 +00:00
|
|
|
#define FG_MSG _(L"Send job %d (%ls) to foreground\n")
|
2016-04-19 02:25:12 +00:00
|
|
|
|
2016-08-16 22:30:49 +00:00
|
|
|
bool builtin_exists(const wcstring &cmd);
|
2016-04-19 02:25:12 +00:00
|
|
|
|
2021-02-14 21:15:29 +00:00
|
|
|
proc_status_t builtin_run(parser_t &parser, const wcstring_list_t &argv, io_streams_t &streams);
|
2016-04-19 02:25:12 +00:00
|
|
|
|
2015-07-28 01:45:47 +00:00
|
|
|
wcstring_list_t builtin_get_names();
|
2020-01-16 00:13:41 +00:00
|
|
|
void builtin_get_names(completion_list_t *list);
|
2019-11-19 00:54:36 +00:00
|
|
|
const wchar_t *builtin_get_desc(const wcstring &name);
|
2005-09-20 13:26:39 +00:00
|
|
|
|
2012-11-19 00:30:30 +00:00
|
|
|
wcstring builtin_help_get(parser_t &parser, const wchar_t *cmd);
|
2006-06-13 13:43:28 +00:00
|
|
|
|
2020-03-13 20:59:10 +00:00
|
|
|
void builtin_print_help(parser_t &parser, const io_streams_t &streams, const wchar_t *name,
|
2019-10-20 09:38:17 +00:00
|
|
|
wcstring *error_message = nullptr);
|
2016-04-21 06:00:54 +00:00
|
|
|
int builtin_count_args(const wchar_t *const *argv);
|
|
|
|
|
|
|
|
void builtin_unknown_option(parser_t &parser, io_streams_t &streams, const wchar_t *cmd,
|
2021-10-19 15:43:54 +00:00
|
|
|
const wchar_t *opt, bool print_hints = true);
|
2016-04-21 06:00:54 +00:00
|
|
|
|
|
|
|
void builtin_missing_argument(parser_t &parser, io_streams_t &streams, const wchar_t *cmd,
|
2020-01-08 16:33:36 +00:00
|
|
|
const wchar_t *opt, bool print_hints = true);
|
2016-04-21 06:00:54 +00:00
|
|
|
|
2019-03-26 18:13:01 +00:00
|
|
|
void builtin_print_error_trailer(parser_t &parser, output_stream_t &b, const wchar_t *cmd);
|
|
|
|
|
2021-10-31 10:51:16 +00:00
|
|
|
void builtin_wperror(const wchar_t *program_name, io_streams_t &streams);
|
2017-06-15 01:25:51 +00:00
|
|
|
|
2017-06-17 03:42:33 +00:00
|
|
|
struct help_only_cmd_opts_t {
|
2017-06-15 01:25:51 +00:00
|
|
|
bool print_help = false;
|
|
|
|
};
|
2021-02-14 02:41:09 +00:00
|
|
|
int parse_help_only_cmd_opts(help_only_cmd_opts_t &opts, int *optind, int argc,
|
|
|
|
const wchar_t **argv, parser_t &parser, io_streams_t &streams);
|
2005-10-04 15:11:39 +00:00
|
|
|
#endif
|