Skip to content

Commit

Permalink
allow specifying std_out and std_error for flowr calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellpeck committed Oct 7, 2024
1 parent 9b6fd85 commit 3c709e1
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 17 deletions.
34 changes: 22 additions & 12 deletions R/flowr_local.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ install_node <- function(node_ver, verbose = FALSE, base_dir = get_default_node_
#' @param flowr_ver The version of flowR to install.
#' @param verbose Whether to print out information about the commands being executed.
#' @param base_dir The base directory that Node was installed in, and where flowR should be installed. By default, this uses the package's installation directory through [get_default_node_base_dir()].
#' @param std_out The std_out parameter passed to the sys call. See [sys::exec_background()] and [sys::exec_wait()] for more info.
#' @param std_err The std_err parameter passed to the sys call. See [sys::exec_background()] and [sys::exec_wait()] for more info.
#' @return The return value of the [exec_node_command()] call.
#'
#' @export
install_flowr <- function(flowr_ver, verbose = FALSE, base_dir = get_default_node_base_dir()) {
exec_node_command("npm", c("install", "-g", paste0("--prefix=", get_node_exe_dir(base_dir)), paste0("@eagleoutice/flowr@", flowr_ver)), verbose, base_dir)
install_flowr <- function(flowr_ver, verbose = FALSE, base_dir = get_default_node_base_dir(), std_out = TRUE, std_err = TRUE) {
exec_node_command("npm", c("install", "-g", paste0("--prefix=", get_node_exe_dir(base_dir)), paste0("@eagleoutice/flowr@", flowr_ver)), verbose, base_dir, FALSE, std_out, std_err)
}

#' Executes a local version of the flowR CLI with the given arguments in the given directory.
Expand All @@ -69,14 +71,16 @@ install_flowr <- function(flowr_ver, verbose = FALSE, base_dir = get_default_nod
#' @param verbose Whether to print out information about the commands being executed.
#' @param base_dir The base directory that Node and flowR were installed in. By default, this uses the package's installation directory through [get_default_node_base_dir()].
#' @param background Whether the command should be executed as a background process.
#' @param std_out The std_out parameter passed to the sys call. See [sys::exec_background()] and [sys::exec_wait()] for more info.
#' @param std_err The std_err parameter passed to the sys call. See [sys::exec_background()] and [sys::exec_wait()] for more info.
#' @return The return value of the [exec_node_command()] call, which is the exit code if background is false, or the pid if background is true.
#'
#' @export
exec_flowr <- function(args, verbose = FALSE, base_dir = get_default_node_base_dir(), background = FALSE) {
exec_flowr <- function(args, verbose = FALSE, base_dir = get_default_node_base_dir(), background = FALSE, std_out = TRUE, std_err = TRUE) {
# we installed flowr globally (see above) in the scope of our local node installation, so we can find it here
node_modules <- if (get_os() == "win") "node_modules" else file.path("lib", "node_modules")
flowr_path <- file.path(get_node_exe_dir(base_dir), node_modules, "@eagleoutice", "flowr", "cli", "flowr.js")
exec_node_command("node", c(flowr_path, args), verbose, base_dir, background)
exec_node_command("node", c(flowr_path, args), verbose, base_dir, background, std_out, std_err)
}

#' Executes a local version of the flowR CLI with the given arguments in the given directory.
Expand All @@ -88,11 +92,13 @@ exec_flowr <- function(args, verbose = FALSE, base_dir = get_default_node_base_d
#' @param verbose Whether to print out information about the commands being executed.
#' @param cmd The command to use for docker. Defaults to "docker".
#' @param background Whether the command should be executed as a background process.
#' @param std_out The std_out parameter passed to the sys call. See [sys::exec_background()] and [sys::exec_wait()] for more info.
#' @param std_err The std_err parameter passed to the sys call. See [sys::exec_background()] and [sys::exec_wait()] for more info.
#' @return The return value of the [exec_node_command()] call, which is the exit code if background is false, or the pid if background is true.
#'
#' @export
exec_flowr_docker <- function(docker_args, flowr_ver, flowr_args, verbose = FALSE, cmd = "docker", background = FALSE) {
exec_docker_command(c("run", "--rm", docker_args, paste0("eagleoutice/flowr:", flowr_ver), flowr_args), verbose, cmd, background)
exec_flowr_docker <- function(docker_args, flowr_ver, flowr_args, verbose = FALSE, cmd = "docker", background = FALSE, std_out = TRUE, std_err = TRUE) {
exec_docker_command(c("run", "--rm", docker_args, paste0("eagleoutice/flowr:", flowr_ver), flowr_args), verbose, cmd, background, std_out, std_err)
}

#' Executes the given Node subcommand in the given arguments in the given directory.
Expand All @@ -103,20 +109,22 @@ exec_flowr_docker <- function(docker_args, flowr_ver, flowr_args, verbose = FALS
#' @param verbose Whether to print out information about the commands being executed.
#' @param base_dir The base directory that Node was installed in. By default, this uses the package's installation directory through [get_default_node_base_dir()].
#' @param background Whether the command should be executed as a background process.
#' @param std_out The std_out parameter passed to the sys call. See [sys::exec_background()] and [sys::exec_wait()] for more info.
#' @param std_err The std_err parameter passed to the sys call. See [sys::exec_background()] and [sys::exec_wait()] for more info.
#' @return The return value of the call, which is the exit code if background is false, or the pid if background is true.
#'
#' @export
exec_node_command <- function(app = c("node", "npm", "npx"), args, verbose = FALSE, base_dir = get_default_node_base_dir(), background = FALSE) {
exec_node_command <- function(app = c("node", "npm", "npx"), args, verbose = FALSE, base_dir = get_default_node_base_dir(), background = FALSE, std_out = TRUE, std_err = TRUE) {
# linux/mac have binaries in the bin subdirectory, windows has node.exe and npm/npx.cmd in the root, bleh
path <- if (get_os() == "win") paste0(app, if (app == "node") ".exe" else ".cmd") else file.path("bin", app)
cmd <- file.path(get_node_exe_dir(base_dir), path)
if (verbose) {
print(paste0("Executing ", cmd, " ", paste0(args, collapse = " ")))
}
if (background) {
return(sys::exec_background(cmd, args))
return(sys::exec_background(cmd, args, std_out, std_err))
} else {
return(sys::exec_wait(cmd, args))
return(sys::exec_wait(cmd, args, std_out, std_err))
}
}

Expand All @@ -127,17 +135,19 @@ exec_node_command <- function(app = c("node", "npm", "npx"), args, verbose = FAL
#' @param verbose Whether to print out information about the commands being executed.
#' @param cmd The command to use for docker. Defaults to "docker".
#' @param background Whether the command should be executed as a background process.
#' @param std_out The std_out parameter passed to the sys call. See [sys::exec_background()] and [sys::exec_wait()] for more info.
#' @param std_err The std_err parameter passed to the sys call. See [sys::exec_background()] and [sys::exec_wait()] for more info.
#' @return The return value of the call, which is the exit code if background is false, or the pid if background is true.
#'
#' @export
exec_docker_command <- function(args, verbose = FALSE, cmd = "docker", background = FALSE) {
exec_docker_command <- function(args, verbose = FALSE, cmd = "docker", background = FALSE, std_out = TRUE, std_err = TRUE) {
if (verbose) {
print(paste0("Executing ", cmd, " ", paste0(args, collapse = " ")))
}
if (background) {
return(sys::exec_background(cmd, args))
return(sys::exec_background(cmd, args, std_out, std_err))
} else {
return(sys::exec_wait(cmd, args))
return(sys::exec_wait(cmd, args, std_out, std_err))
}
}

Expand Down
13 changes: 12 additions & 1 deletion man/exec_docker_command.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion man/exec_flowr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion man/exec_flowr_docker.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion man/exec_node_command.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion man/install_flowr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3c709e1

Please sign in to comment.