R/cli.R

Defines functions windowsPath cli

Documented in cli

#' Install the command line interface
# Inspired by: https://github.com/ankane/jetpack/blob/master/R/cli.R
#' @export
#' @examples \dontrun{
#' showpackage::cli()
#' }
cli <- function() {
  if (.Platform$OS.type != "unix") {
    file <- "C:/ProgramData/showpackage/bin/showpackage.cmd"
    rscript <- file.path(R.home("bin"), "Rscript.exe")
    dir <- dirname(file)
    if (!file.exists(dir)) {
      dir.create(dir, recursive=TRUE)
    }
    write(paste0("@", rscript, " -e \"showpackage::run()\" %* "), file = file)
    message(paste("Wrote", windowsPath(file)))
    message(paste0("Be sure to add '", windowsPath(dir), "' to your PATH"))
  } else {
    file <- "/usr/local/bin/showpackage"
    write("#!/usr/bin/env Rscript\n\nshowpackage::run()", file = file)
    Sys.chmod(file, "755")
    message(paste("Wrote", file))
  }
}

windowsPath <- function(path) {
  gsub("/", "\\\\", path)
}
RobertMyles/showpackage documentation built on Sept. 7, 2021, 6:45 a.m.