mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-02-19 06:12:44 +08:00
printf: Ignore any options
This was misguidedly "fixed" in
9e08609f85
, which made printf error out
with any "-"-prefixed words as the first argument.
Note: This means currently `printf --help` doesn't print the help.
This also matches `echo`, and we currently don't have anything to make
a literal `--help` execute a builtin help except for keywords. Oh well.
Fixes #9132
This commit is contained in:
parent
c288443b4d
commit
37f7818bbb
|
@ -649,19 +649,10 @@ int builtin_printf_state_t::print_formatted(const wchar_t *format, int argc, con
|
|||
maybe_t<int> builtin_printf(parser_t &parser, io_streams_t &streams, const 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;
|
||||
argv++;
|
||||
argc--;
|
||||
|
||||
if (opts.print_help) {
|
||||
builtin_print_help(parser, streams, cmd);
|
||||
return STATUS_CMD_OK;
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
if (argc < 1) {
|
||||
return STATUS_INVALID_ARGS;
|
||||
}
|
||||
|
|
|
@ -119,3 +119,18 @@ printf '%d\n' 0g
|
|||
# CHECKERR: 0g: value not completely converted (can't convert 'g')
|
||||
echo $status
|
||||
# CHECK: 1
|
||||
|
||||
# Test that we ignore options
|
||||
printf -a
|
||||
printf --foo
|
||||
# CHECK: -a--foo
|
||||
echo
|
||||
|
||||
set -l helpvar --help
|
||||
printf $helpvar
|
||||
echo
|
||||
# CHECK: --help
|
||||
|
||||
printf --help
|
||||
echo
|
||||
# CHECK: --help
|
||||
|
|
Loading…
Reference in New Issue
Block a user