trevorld / r-argparse

Compare 10390d8 ... +1 ... df16a0b

Coverage Reach
argparse.R

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 1 of 10 files from the diff.
Other files ignored by Codecov

@@ -118,7 +118,7 @@
Loading
118 118
            private$n_subparsers <- private$n_subparsers + 1
119 119
            private$python_code$append(sprintf("%s = %s.add_parser(%s)",
120 120
                            parser_name, private$name,
121 -
                            convert_..._to_arguments("add_argument", ...)))
121 +
                            convert_..._to_arguments("ArgumentParser", ...)))
122 122
            Parser$new(private$python_code, parser_name)
123 123
        }
124 124
    ),
@@ -150,8 +150,7 @@
Loading
150 150
                .stop(message, "non-ascii character error:")
151 151
            } else if (any(grepl("^SyntaxError: positional argument follows keyword argument", output)) ||
152 152
                       grepl("^SyntaxError: non-keyword arg after keyword arg", output[2])) {
153 -
                message <- paste("Positional argument following keyword argument.",
154 -
                                 "Please note ``ArgumentParser`` only accepts keyword arguments.")
153 +
                message <- "Positional argument following keyword argument."
155 154
                .stop(message, "syntax error:")
156 155
            } else if (grepl("^\\{", output)) {
157 156
                args <- jsonlite::fromJSON(paste(output, collapse = ""))
@@ -240,7 +239,7 @@
Loading
240 239
    argument_list <- list(...)
241 240
    argument_names <- names(argument_list)
242 241
    if (is.null(argument_names))
243 -
        argument_names <- rep("", length(argument_list))
242 +
        argument_names <- rep_len("", length(argument_list))
244 243
    equals <- ifelse(argument_names == "", "", "=")
245 244
    proposed_arguments <- c()
246 245
    for (ii in seq_along(argument_list)) {
@@ -264,14 +263,26 @@
Loading
264 263
    }
265 264
    # Set right default prog name if not specified, if possible
266 265
    # Do last to not screw up other fixes with prog insertion
267 -
    if (mode == "ArgumentParser" && all(!grepl("prog=", proposed_arguments))) {
266 +
    if (mode == "ArgumentParser" && needs_prog(argument_names)) {
268 267
        prog <- get_Rscript_filename()
269 268
        if (is.na(prog)) prog <- "PROGRAM"
270 269
        proposed_arguments <- c(sprintf("prog='%s'", prog), proposed_arguments)
271 270
    }
272 271
    return(paste(proposed_arguments, collapse = ", "))
273 272
}
274 273
274 +
needs_prog <- function(argument_names) {
275 +
    if (length(argument_names) == 0L) {
276 +
        TRUE
277 +
    } else if (argument_names[1L] == "") {
278 +
        FALSE
279 +
    } else if (any(argument_names == "prog")) {
280 +
        FALSE
281 +
    } else {
282 +
        TRUE
283 +
    }
284 +
}
285 +
275 286
# Manually copied over from getopt to eliminate it as a dependency
276 287
get_Rscript_filename <- function() { # nolint
277 288
    prog <- sub("--file=", "", grep("--file=", commandArgs(), value = TRUE)[1])

Learn more Showing 1 files with coverage changes found.

Changes in R/argparse.R
-4
+4
Loading file...
Files Coverage
R/argparse.R -4.44% 94.23%
Project Totals (1 files) 94.23%
Loading