Skip to content

Commit

Permalink
remove cli and rlang
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed Jan 16, 2024
1 parent 97014ff commit bf22465
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
4 changes: 1 addition & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ RoxygenNote: 7.2.3
Config/rextendr/version: 0.3.1.9000
SystemRequirements: Cargo (Rust's package manager), rustc
Imports:
blob,
cli,
rlang
blob
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
11 changes: 5 additions & 6 deletions R/alphabet.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
#' new_alphabet("qwertyuiop[]asdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890")
#' @returns an object of class `alphabet`
alphabet <- function(which = "standard") {
rlang::arg_match(
match.arg(
which,
values = c("standard", "bcrypt", "bin_hex", "crypt", "imap_mutf7", "url_safe")
choices = c("standard", "bcrypt", "bin_hex", "crypt", "imap_mutf7", "url_safe")
)
structure(alphabet_(which), class = "alphabet")
}
Expand All @@ -42,10 +42,9 @@ alphabet <- function(which = "standard") {
new_alphabet <- function(chars) {
n <- nchar(chars)
if (nchar(chars) != 64) {
cli::cli_abort(
c(
"{.arg chars} must be 64 unique characters",
"i" = "{n} characters provided"
stop(
paste(
"`chars` must contain 64 unique characters. Only", n, "characters were provided."
)
)
}
Expand Down
4 changes: 2 additions & 2 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ new_config <- function(
decode_padding_mode = c("canonical", "indifferent", "none")
) {

padding_mode <- rlang::arg_match0(
padding_mode <- match.arg(
decode_padding_mode,
values = c("canonical", "indifferent", "none")
choices = c("canonical", "indifferent", "none")
)

res <- new_config_(
Expand Down
4 changes: 2 additions & 2 deletions R/encode.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ decode <- function(what, eng = engine()) {
#' @name encode
encode_file <- function(path, eng = engine()) {
if (!file.exists(path)) {
cli::cli_abort("{.arg path} does not exist")
stop(paste0("`", path, "` does not exist"))
}

encode_file_(path, eng)
Expand All @@ -56,7 +56,7 @@ encode_file <- function(path, eng = engine()) {
#' @rdname encode
decode_file <- function(path, eng = engine()) {
if (!file.exists(path)) {
cli::cli_abort("{.arg path} does not exist")
stop(paste0("`", path, "` does not exist"))
}

decode_file_(path, eng)
Expand Down
22 changes: 11 additions & 11 deletions R/engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@
#' new_engine(alphabet("bcrypt"), new_config())
engine <- function(which = "standard") {
provided <- c("standard", "standard_no_pad", "url_safe", "url_safe_no_pad")
rlang::arg_match0(which, provided)
match.arg(which, choices = provided)
structure(engine_(which), class = "engine")
}

#' @export
#' @rdname engine
new_engine <- function(.alphabet = alphabet(), .config = new_config()) {

if (!rlang::inherits_only(.alphabet, "alphabet")) {
cli::cli_abort(
c(
"{.arg .alphabet} is not an object of class {.cls alphabet}",
"*" = "use {.fn alphabet} for a standard base64 alphabet"
if (!inherits(.alphabet, "alphabet")) {
stop(
paste(
"`.alphabet` is not an object of class 'alphabet'.\n" ,
"Use `alphabet()` for a standard base64 alphabet."
)
)
} else if (!rlang::inherits_only(.config, "engine_config")) {
cli::cli_abort(
c(
"{.arg config} is not a {.cls engine_config} object",
"*" = "create one with {.fn new_config}"
} else if (!inherits(.config, "engine_config")) {
stop(
paste(
"`.config` is not an object of class 'engine_config'.\n" ,
"Create one with `new_config()`."
)
)
}
Expand Down

0 comments on commit bf22465

Please sign in to comment.