Skip to content

Commit decad3d

Browse files
Fix for bare cli args like --cascade to be TRUE, not NA
1 parent 70f32bd commit decad3d

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

R/cli_functions.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ parse_cli_args <- function(args, sep = "/", type_values = TRUE) {
191191
# always collapse into a single string to avoid continuation errors in args_to_df
192192
if (length(args) > 1L) args <- paste(args, collapse = " ")
193193
df <- args_to_df(args)
194+
# Treat bare options (e.g. "--flag") as logical TRUE.
195+
bare_flag_idx <- !df$has_equals & is.na(df$rhs)
196+
if (any(bare_flag_idx)) df$rhs[bare_flag_idx] <- "TRUE"
194197
assignments <- paste(df$lhs, df$rhs, sep="=")
195198
set_nested_values(assignments, sep = sep, type_values = type_values)
196199
}

inst/upd_job_status.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ args <- BrainGnomes::parse_cli_args(tmp)
4141
if (isTRUE(args$job_id == "NULL")) args$job_id <- NULL
4242
if (isTRUE(args$sqlite_db == "NULL")) args$sqlite_db <- NULL
4343
if (isTRUE(args$status == "NULL")) args$status <- NULL
44-
if (isTRUE(args$cascade == "NULL") | isTRUE(is.null(args$cascade))) args$cascade <- FALSE
44+
args$cascade <- isTRUE(args$cascade)
4545
if (isTRUE(args$output_dir == "NULL")) args$output_dir <- NULL
4646

4747
# Capture output manifest if status is COMPLETED and output_dir is provided

tests/testthat/test-cli_utils.R

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ test_that("parse_cli_args handles embedded equals signs", {
3333
expect_equal(res$bar, "a = b")
3434
})
3535

36+
test_that("parse_cli_args treats bare flags as TRUE", {
37+
res <- parse_cli_args(c("--status FAILED", "--cascade"))
38+
expect_equal(res$status, "FAILED")
39+
expect_true(isTRUE(res$cascade))
40+
})
41+
42+
test_that("parse_cli_args respects explicit FALSE and NULL for flags", {
43+
expect_false(parse_cli_args(c("--cascade=FALSE"))$cascade)
44+
expect_null(parse_cli_args(c("--cascade=NULL"))$cascade)
45+
})
46+
3647
# nested_list_to_args round-trips with parse_cli_args
3748

3849
test_that("nested_list_to_args creates expected CLI strings", {
@@ -53,4 +64,3 @@ test_that("set_cli_options updates and adds options", {
5364
# expect_equal(result, c("--foo=3", "--bar=2", "--baz=4"))
5465
expect_equal(result, c("--foo=3 --baz=4 --bar=2"))
5566
})
56-

0 commit comments

Comments
 (0)