Skip to content

Commit cbc5784

Browse files
committed
Address boolean alias review findings
1 parent 4f4aa87 commit cbc5784

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

R/args.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ process_args <- function(args, app) {
101101
) {
102102
stop_unrecognized_arg(a)
103103
}
104+
if (is.null(spec) && startsWith(a, "--no-")) {
105+
alt_name <- str_drop_prefix(name, "no_")
106+
alt_spec <- app_opts[[alt_name]]
107+
if (
108+
!is.null(alt_spec) &&
109+
identical(alt_spec$arg_type, "switch") &&
110+
!has_negative_alias(alt_spec)
111+
) {
112+
stop_unrecognized_arg(a)
113+
}
114+
}
104115
} else {
105116
# --name
106117
name <- str_drop_prefix(a, "--")

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ To omit the generated `--no-*` alias for a boolean switch, add
139139
``` r
140140
#| description: Print version and exit.
141141
#| negative_alias: false
142-
version <- TRUE
142+
version <- FALSE
143143
```
144144

145145
Rapp parses option values as YAML 1.2, where bare `yes` and `no` are

tests/testthat/test-regressions.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ test_that("disabled boolean aliases are rejected before positional matching", {
269269
"Arguments not recognized: --no-flag",
270270
fixed = TRUE
271271
)
272+
expect_error(
273+
Rapp::run(false_default_app, "--no-flag=false"),
274+
"Arguments not recognized: --no-flag=false",
275+
fixed = TRUE
276+
)
272277
})
273278

274279
test_that("YAML 1.2 strings are preserved in parsed option values", {

0 commit comments

Comments
 (0)