R/run.R

Defines functions run

Documented in run

#' Run the command line interface
# Inspired by: https://github.com/ankane/jetpack/blob/master/R/run.R
#' @export
#' @keywords internal
run <- function() {

  doc <- "Usage:
    showpackage <package>
    showpackage help"
  
  opts <- NULL
  tryCatch({
    opts <- docopt::docopt(doc)
    }, error = function(err){
    msg <- conditionMessage(err)
    if (!grepl("usage:", msg)) {
      warn(msg)
    }
    message(doc)
    quit(status = 1)
  })
  
  tryCatch({
    if(opts$help){
      message(doc)
      } else{
      show_pkg(package = opts$package)
        }
    }, error=function(err) {
      msg <- conditionMessage(err)
      quit(status = 1)
    })
}
RobertMyles/showpackage documentation built on Sept. 7, 2021, 6:45 a.m.