mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 05:43:11 +00:00
functions: Add "--no-details" flag and use it in funced
This inhibits the function path comment which is annoying in `funced`. Fixes #7879.
This commit is contained in:
parent
da2f7999ad
commit
18e332772d
4 changed files with 30 additions and 2 deletions
|
@ -39,6 +39,8 @@ The following options are available:
|
|||
|
||||
You should not assume that only five lines will be written since we may add additional information to the output in the future.
|
||||
|
||||
- ``--no-details`` turns off function path reporting, so just the definition will be printed.
|
||||
|
||||
- ``-n`` or ``--names`` lists the names of all defined functions.
|
||||
|
||||
- ``-q`` or ``--query`` tests if the specified functions exist.
|
||||
|
|
|
@ -60,7 +60,7 @@ function funced --description 'Edit function definition'
|
|||
|
||||
if test "$editor" = fish
|
||||
if functions -q -- $funcname
|
||||
functions -- $funcname | fish_indent --no-indent | read -z init
|
||||
functions --no-details -- $funcname | fish_indent --no-indent | read -z init
|
||||
end
|
||||
|
||||
set -l prompt 'printf "%s%s%s> " (set_color green) '$funcname' (set_color normal)'
|
||||
|
|
|
@ -40,6 +40,7 @@ struct functions_cmd_opts_t {
|
|||
bool query = false;
|
||||
bool copy = false;
|
||||
bool report_metadata = false;
|
||||
bool no_metadata = false;
|
||||
bool verbose = false;
|
||||
bool handlers = false;
|
||||
const wchar_t *handlers_type = nullptr;
|
||||
|
@ -54,6 +55,7 @@ static const struct woption long_options[] = {{L"erase", no_argument, nullptr, '
|
|||
{L"query", no_argument, nullptr, 'q'},
|
||||
{L"copy", no_argument, nullptr, 'c'},
|
||||
{L"details", no_argument, nullptr, 'D'},
|
||||
{L"no-details", no_argument, nullptr, 1},
|
||||
{L"verbose", no_argument, nullptr, 'v'},
|
||||
{L"handlers", no_argument, nullptr, 'H'},
|
||||
{L"handlers-type", required_argument, nullptr, 't'},
|
||||
|
@ -78,6 +80,10 @@ static int parse_cmd_opts(functions_cmd_opts_t &opts, int *optind, //!OCLINT(hi
|
|||
opts.report_metadata = true;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
opts.no_metadata = true;
|
||||
break;
|
||||
}
|
||||
case 'd': {
|
||||
opts.description = w.woptarg;
|
||||
break;
|
||||
|
@ -206,6 +212,12 @@ maybe_t<int> builtin_functions(parser_t &parser, io_streams_t &streams, const wc
|
|||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (opts.report_metadata && opts.no_metadata) {
|
||||
streams.err.append_format(BUILTIN_ERR_COMBO, cmd);
|
||||
builtin_print_error_trailer(parser, streams.err, cmd);
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (opts.erase) {
|
||||
for (int i = optind; i < argc; i++) function_remove(argv[i]);
|
||||
return STATUS_CMD_OK;
|
||||
|
@ -335,7 +347,9 @@ maybe_t<int> builtin_functions(parser_t &parser, io_streams_t &streams, const wc
|
|||
if (!opts.query) {
|
||||
if (i != optind) streams.out.append(L"\n");
|
||||
const wchar_t *funcname = argv[i];
|
||||
report_function_metadata(funcname, opts.verbose, streams, parser, true);
|
||||
if (!opts.no_metadata) {
|
||||
report_function_metadata(funcname, opts.verbose, streams, parser, true);
|
||||
}
|
||||
wcstring def = functions_def(funcname);
|
||||
|
||||
if (!streams.out_is_redirected && isatty(STDOUT_FILENO)) {
|
||||
|
|
|
@ -105,3 +105,15 @@ functions t
|
|||
# CHECK: echo tttt;
|
||||
# CHECK: end
|
||||
|
||||
functions --no-details t
|
||||
# CHECK: function t
|
||||
# CHECK: echo tttt;
|
||||
# CHECK: end
|
||||
|
||||
functions --no-details --details t
|
||||
# CHECKERR: functions: Invalid combination of options
|
||||
# CHECKERR:
|
||||
# CHECKERR: checks/functions.fish (line {{\d+}}):
|
||||
# CHECKERR: functions --no-details --details t
|
||||
# CHECKERR: ^
|
||||
# CHECKERR: (Type 'help functions' for related documentation)
|
||||
|
|
Loading…
Reference in a new issue