Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string repeat: require explicit -n/--count option only in presence of --max #9332

Closed
floam opened this issue Nov 7, 2022 · 1 comment
Closed

Comments

@floam
Copy link
Member

floam commented Nov 7, 2022

string repeat has this usage signature:

string repeat [(-n | --count) COUNT] [(-m | --max) MAX] [-N | --no-newline]
              [-q | --quiet] [STRING]

The enhancement suggestion is, make string repeat 5 x or echo x | string repeat 5 (which both silently exit status 1 with no error message today) equivalent to string repeat -n 5 x or echo x | string repeat -n 5, taking the first positional argument as COUNT and additional arguments as STRINGs, like how string join takes the first argument as the separator.

> echo x | string repeat 5
xxxxx
> string repeat 5 x
xxxxx

In other words, it should basically behave how you'd expect it to if the usage synopsis had an additional simpler signature:

string repeat [-N | --no-newline] (-q | --quiet] COUNT [STRING …]
string repeat [(-n | --count) COUNT] [(-m | --max) MAX] [-N | --no-newline]
              [-q | --quiet] [STRING]

-n or --count should be required only to distinguish things in the case where a --max is being used, for the sake of things not being ambiguous and it is important that only things that used to error start to work, but things that worked before do not have a change in behavior. This example would needs to have the same output as it does today:

> string repeat 5 x --max 3
555
xxx

i.e. it will still be necessary to explicitly specify a --count option:

> string repeat --count 5 x --max 3
xxx

The motivation here is to make string repeat easier to figure out and remember how to use, taking into consideration --max is a rare thing.

@ridiculousfish
Copy link
Member

This makes sense to me; today string repeat 3 foo does nothing useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants