Closed kbvernon closed 3 months ago
Yes definitely! You should definitely do this. We do not need to have all the arguments to the CLI either. Just the most common ones. If you need things like optional or nightly etc then you probably wont need an R package to help!
Here's some start code we can use:
compact <- function(.x) Filter(length, .x)
use_crate <- function(crate, features = NULL, git = NULL, path = ".") {
# TODO check arguments and that they are the right type and length
# consider adding standalone type checks
# get source directory
src_dir <- rprojroot::find_package_root_file(path, "src/rust")
# craft additional args
cargo_add_opts <- compact(list(
"--features" = features,
"--git" = git
))
# craft the additional arguments
adtl_args <- unname(unlist(Map(
function(.x, .nm) {
paste(.nm, paste0(.x, collapse = " "))
},
cargo_add_opts,
names(cargo_add_opts)
)))
# run the commmand
processx::run(
"cargo",
c("add", crate, adtl_args),
echo_cmd = TRUE,
wd = src_dir
)
}
Thanks, @JosiahParry! I'll try to get a PR together this evening.
But also, what about adding an options
parameter that would take a named list to catch all the other flags?
my preference would be to use ...
and use rlang::dots_list()
to capture the others!
@kbvernon , did your PR resolve this issue or are you planning on adding more features?
Ah, yeah, this issue is resolved with https://github.com/extendr/rextendr/pull/361. Sorry, I forgot to close it!
Similar to
usethis::use_package()
but for adding dependencies to Cargo.toml.Happy to contribute a PR for this if you all think it is worthwhile.