R/cli_helpers.R

Defines functions style_valid_types style_cli_vec

# ---------------------------------------------------------------------------- #

utils::globalVariables(c("style_cli_vec"))
utils::globalVariables(c("style_valid_types"))

# ---------------------------------------------------------------------------- #
#' Add specific cli style to a vector
#'
#' @param vec Vector that will be collapsed by cli.
#' @param sep The separator to use for collapsing \code{vec}.
#'
#' @examples
#' style_cli_vec(c("a", "b"))
#' style_cli_vec(c("a", "b"), " | ")
#'
#' @keywords internal
#' @noRd
style_cli_vec <- function(vec, sep = ", ") {
  cli::cli_vec(vec, style = list("vec-sep" = sep, "vec-last" = sep))
}

# ---------------------------------------------------------------------------- #
#' Add cli style to a vector of valid type strings
#'
#' Creates an object suitable for passing to `cli::cli_abort` from a vector of
#'   valid type strings.
#'
#' @param vec A vector of valid type strings  (in the sense of an enumerated
#'   type).
#'
#' @return The result of calling cli::cli_vec.
#'
#' @examples
#' style_valid_types(c("one", "two", "three"))
#'
#' @keywords internal
#' @noRd
style_valid_types <- function(vec) {
  style_cli_vec(vec, " | ")
}

# ---------------------------------------------------------------------------- #
toniprice/jute documentation built on Jan. 11, 2023, 8:23 a.m.