mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-26 03:35:17 +00:00
Let read -s
also output to stdout
This was caused by "to_stdout" being automatically enabled if argc was 0 _before_ removing options. Fixes #4859.
This commit is contained in:
parent
ea49c14c62
commit
d53750bee6
1 changed files with 10 additions and 6 deletions
|
@ -73,11 +73,6 @@ static const struct woption long_options[] = {{L"export", no_argument, NULL, 'x'
|
||||||
|
|
||||||
static int parse_cmd_opts(read_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
static int parse_cmd_opts(read_cmd_opts_t &opts, int *optind, //!OCLINT(high ncss method)
|
||||||
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
int argc, wchar_t **argv, parser_t &parser, io_streams_t &streams) {
|
||||||
if (argc == 1) {
|
|
||||||
opts.to_stdout = true;
|
|
||||||
return STATUS_CMD_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
wchar_t *cmd = argv[0];
|
wchar_t *cmd = argv[0];
|
||||||
int opt;
|
int opt;
|
||||||
wgetopter_t w;
|
wgetopter_t w;
|
||||||
|
@ -372,7 +367,7 @@ static int validate_read_args(const wchar_t *cmd, read_cmd_opts_t &opts, int arg
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opts.array && argc < 1) {
|
if (!opts.array && argc < 1 && !opts.to_stdout) {
|
||||||
streams.err.append_format(BUILTIN_ERR_MIN_ARG_COUNT1, cmd, 1, argc);
|
streams.err.append_format(BUILTIN_ERR_MIN_ARG_COUNT1, cmd, 1, argc);
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
|
@ -382,6 +377,11 @@ static int validate_read_args(const wchar_t *cmd, read_cmd_opts_t &opts, int arg
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opts.to_stdout && argc > 0) {
|
||||||
|
streams.err.append_format(BUILTIN_ERR_MAX_ARG_COUNT1, cmd, 0, argc);
|
||||||
|
return STATUS_INVALID_ARGS;
|
||||||
|
}
|
||||||
|
|
||||||
// Verify all variable names.
|
// Verify all variable names.
|
||||||
for (int i = 0; i < argc; i++) {
|
for (int i = 0; i < argc; i++) {
|
||||||
if (!valid_var_name(argv[i])) {
|
if (!valid_var_name(argv[i])) {
|
||||||
|
@ -410,6 +410,10 @@ int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
argv += optind;
|
argv += optind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (argc == 0) {
|
||||||
|
opts.to_stdout = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (opts.print_help) {
|
if (opts.print_help) {
|
||||||
builtin_print_help(parser, streams, cmd, streams.out);
|
builtin_print_help(parser, streams, cmd, streams.out);
|
||||||
return STATUS_CMD_OK;
|
return STATUS_CMD_OK;
|
||||||
|
|
Loading…
Reference in a new issue