cli
cli copied to clipboard
`vec-last` ignored when only 2 elements are provided
cli_vec()
is very helpful when informing uses that they should choose one of a set of values. Using vec-last
is great because it allows us to say or {last-item}
meaning it is one of the options not all of them. However, when only two elements are provided cli_vec()
always says "and".
Can it be fixed such that vec-last
is used when the vector length is > 1?
v <- cli::cli_vec(
c("foo", "bar", "foobar"),
style = list("vec-last" = ", or ")
)
cli::cli_text("Must be one of: {v}.")
#> Must be one of: foo, bar, or foobar.
v <- cli::cli_vec(
c("foo", "bar"),
style = list("vec-last" = " or ")
)
cli::cli_text("Must be one of: {v}.")
#> Must be one of: foo and bar.
Created on 2024-03-21 with reprex v2.0.2
Hi! I would also appreciate a fix for this problem. Thanks for the great package and all the work you are putting in.
Kind regards Adrian
Fixing this is probably a breaking change.
There is also a workaround already:
v <- cli::cli_vec(
c("foo", "bar"),
style = list("vec-last" = " or ", "vec-sep2" = " or ")
)
cli::cli_text("Must be one of: {v}.")
Must be one of: foo or bar.
which is also appropriate if you want Oxford comma:
v <- cli::cli_vec(
c("foo", "bar"),
style = list("vec-last" = ", or ", "vec-sep2" = " or ")
)
cli::cli_text("Must be one of: {v}.")
Another workaround is to use the .or
class:
v <- c("foo", "bar")
cli::cli_text("Must be one of: {.or {v}}.")
Must be one of: foo or bar.
Closed by #718.