|
2 | 2 | #' |
3 | 3 | #' Make a new [scribeCommandArgs] object |
4 | 4 | #' |
5 | | -#' @param x,string Command line arguments; see [base::commandArgs()] for |
6 | | -#' default. At least one parameter has to be `NULL`. When `string` is |
7 | | -#' `NULL`, `x` is used, which defaults to `commandArgs(trailingOnly = TRUE)`. |
8 | | -#' Otherwise the value of `x` is converted to a `character`. If `string` is |
9 | | -#' not `NULL`, [scan()] will be used to split the value into a `character` |
10 | | -#' vector. |
| 5 | +#' @param x Command line arguments as a character vector. Use `I()` to pass a |
| 6 | +#' single (combined) string of arguments. |
11 | 7 | #' @param include Special default arguments to included. See `$initialize()` in |
12 | 8 | #' [scribeCommandArgs] for more details. |
13 | 9 | #' @param super When `TRUE` the [scribeCommandArgs] object will be initialized |
14 | 10 | #' with standard _super_ arguments (e.g., `---help`, `---version`) |
| 11 | +#' @param string Deprecated. Use `command_args(I())` to pass a single string of |
| 12 | +#' arguments. |
15 | 13 | #' @examples |
16 | 14 | #' command_args() |
17 | 15 | #' command_args(c("-a", 1, "-b", 2)) |
18 | | -#' command_args(string = "-a 1 -b 2") |
| 16 | +#' command_args(I("-a 1 -b 2")) |
19 | 17 | #' @returns A [scribeCommandArgs] object |
20 | 18 | #' @family scribe |
21 | 19 | #' @export |
22 | 20 | command_args <- function( |
23 | | - x = NULL, |
| 21 | + x = commandArgs(trailingOnly = TRUE), |
24 | 22 | include = getOption("scribe.include", c("help", "version", NA_character_)), |
25 | | - string = NULL, |
26 | | - super = include |
| 23 | + super = include, |
| 24 | + string |
27 | 25 | ) { |
28 | | - if (is.null(string)) { |
29 | | - if (is.null(x)) { |
30 | | - x <- commandArgs(trailingOnly = TRUE) |
31 | | - } |
32 | | - x <- as.character(x) |
33 | | - } else { |
34 | | - if (!is.null(x)) { |
35 | | - stop("'string' and 'x' cannot both be set", call. = FALSE) |
36 | | - } |
| 26 | + if (!missing(string)) { |
| 27 | + .Deprecated( |
| 28 | + msg = sprintf( |
| 29 | + "command_args(string=) is deprecated. Use command_args(I(\"%s\")) instead.", # nolint: line_length_linter. |
| 30 | + string |
| 31 | + ) |
| 32 | + ) |
| 33 | + x <- I(string) |
| 34 | + } |
37 | 35 |
|
38 | | - string <- as.character(string) |
39 | | - x <- scan(text = string, what = "character", quiet = TRUE) |
| 36 | + if (inherits(x, "AsIs")) { |
| 37 | + x <- scan(text = as.character(x), what = character(), quiet = TRUE) |
40 | 38 | } |
41 | 39 |
|
42 | 40 | scribeCommandArgs(input = x, include = include, super = super) |
|
0 commit comments