Skip to content

Commit 0ed5abb

Browse files
committed
Clarify boolean switch alias helpers
1 parent 2d00c46 commit 0ed5abb

4 files changed

Lines changed: 20 additions & 13 deletions

File tree

R/args.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ process_args <- function(args, app) {
1919
for (i in seq_along(app_opts)) {
2020
if (identical(short, app_opts[[i]][["short"]])) {
2121
if (identical(app_opts[[i]][["arg_type"]], "switch")) {
22-
if (show_positive_alias(app_opts[[i]])) {
22+
if (shows_positive_alias(app_opts[[i]])) {
2323
return(paste0("--", names(app_opts)[[i]]))
2424
}
25-
if (show_negative_alias(app_opts[[i]])) {
25+
if (shows_negative_alias(app_opts[[i]])) {
2626
return(paste0("--no-", names(app_opts)[[i]]))
2727
}
2828
return(paste0("--", names(app_opts)[[i]]))
@@ -99,7 +99,7 @@ process_args <- function(args, app) {
9999
if (
100100
!is.null(spec) &&
101101
identical(spec$arg_type, "switch") &&
102-
!has_positive_alias(spec)
102+
!accepts_positive_alias(spec)
103103
) {
104104
stop_unrecognized_arg(a)
105105
}
@@ -125,7 +125,7 @@ process_args <- function(args, app) {
125125
if (
126126
!is.null(spec) &&
127127
identical(spec$arg_type, "switch") &&
128-
!has_positive_alias(spec)
128+
!accepts_positive_alias(spec)
129129
) {
130130
stop_unrecognized_arg(a)
131131
}
@@ -141,7 +141,7 @@ process_args <- function(args, app) {
141141
!is.null(alt_spec) &&
142142
identical(alt_spec$arg_type, "switch")
143143
) {
144-
if (has_negative_alias(alt_spec)) {
144+
if (accepts_negative_alias(alt_spec)) {
145145
spec <- alt_spec
146146
val <- "false"
147147
name <- alt_name

R/help.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ print_app_help <- function(app, yaml = TRUE, command_path = character()) {
194194
default_value <- format_default_value(opt$default)
195195
positive_flag <- paste0("--", cli_name)
196196
negative_flag <- paste0("--no-", cli_name)
197-
show_positive <- show_positive_alias(opt)
198-
show_negative <- show_negative_alias(opt)
197+
show_positive <- shows_positive_alias(opt)
198+
show_negative <- shows_negative_alias(opt)
199199
if (!show_positive && !show_negative) {
200200
flag <- paste(positive_flag, format_placeholder(name))
201201
if (!is.null(short_flag) && nzchar(short_flag)) {

R/utils.R

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ check_bool_switch_default <- function(default) {
7979
}
8080
}
8181

82-
has_positive_alias <- function(opt) {
82+
# Parsing is intentionally more permissive than help. accepts_* controls
83+
# command-line forms; shows_* controls the concise help surface.
84+
accepts_positive_alias <- function(opt) {
8385
stopifnot(identical(opt[["arg_type"]], "switch"))
8486

8587
default <- opt[["default"]]
@@ -88,7 +90,7 @@ has_positive_alias <- function(opt) {
8890
TRUE
8991
}
9092

91-
has_negative_alias <- function(opt) {
93+
accepts_negative_alias <- function(opt) {
9294
stopifnot(identical(opt[["arg_type"]], "switch"))
9395

9496
default <- opt[["default"]]
@@ -101,7 +103,7 @@ has_negative_alias <- function(opt) {
101103
TRUE
102104
}
103105

104-
show_positive_alias <- function(opt) {
106+
shows_positive_alias <- function(opt) {
105107
stopifnot(identical(opt[["arg_type"]], "switch"))
106108

107109
default <- opt[["default"]]
@@ -110,13 +112,13 @@ show_positive_alias <- function(opt) {
110112
isFALSE(default) || isTRUE(is.na(default))
111113
}
112114

113-
show_negative_alias <- function(opt) {
115+
shows_negative_alias <- function(opt) {
114116
stopifnot(identical(opt[["arg_type"]], "switch"))
115117

116118
default <- opt[["default"]]
117119
check_bool_switch_default(default)
118120

119-
has_negative_alias(opt) && (isTRUE(default) || isTRUE(is.na(default)))
121+
accepts_negative_alias(opt) && (isTRUE(default) || isTRUE(is.na(default)))
120122
}
121123

122124
`append<-` <- function(x, after = NULL, value) {

docs/boolean-options.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Logical defaults become boolean command-line inputs. Help output shows the
44
most useful spelling for changing the default, while parsing also accepts
55
explicit boolean values for convenience.
66

7+
Help output is intentionally narrower than parsing. For example, `foo <- TRUE`
8+
normally shows `--no-foo`, but `--foo=false` is still accepted because it is an
9+
explicit boolean value for `foo`.
10+
711
In the table below, `TRUE`, `FALSE`, and `NA` are the resulting R values.
812
`reject` means the command-line form is not accepted.
913

@@ -23,4 +27,5 @@ value after `--foo`.
2327

2428
`#| negative_alias: false` only disables the generated `--no-foo` spelling.
2529
It does not disable the positive spelling or explicit value forms such as
26-
`--foo=false`.
30+
`--foo=false`. With `foo <- TRUE`, that leaves no default-changing bare alias,
31+
so help shows `--foo <FOO>` as an explicit-value form.

0 commit comments

Comments
 (0)