diff --git a/NAMESPACE b/NAMESPACE index 8eb63aa..f33b2d5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,7 +1,7 @@ # Generated by roxygen2: do not edit by hand export(generate_pkg) -export(pkg_agent) +export(generate_pkg_agent) export(use_beekeeper) if (getRversion() < "4.3.0") importFrom("S7", "@") importFrom(glue,glue) diff --git a/R/generate.R b/R/generate.R index 096054b..a055019 100644 --- a/R/generate.R +++ b/R/generate.R @@ -11,7 +11,7 @@ #' @return `TRUE` invisibly. #' @export generate_pkg <- function(config_file = "_beekeeper.yml", - pkg_agent = pkg_agent(fs::path_dir(config_file))) { + pkg_agent = generate_pkg_agent(config_file)) { .assert_is_pkg() config <- .read_config(config_file) api_definition <- readRDS( @@ -107,27 +107,3 @@ generate_pkg <- function(config_file = "_beekeeper.yml", return(invisible(target)) } - -#' Create a user agent for the active package -#' -#' @param path The path to the DESCRIPTION file, or to a directory within a -#' package. -#' -#' @return A string with the name of the package and (if available) the first -#' URL associated with the package. -#' -#' @export -pkg_agent <- function(path = ".") { - pkg_desc <- desc::desc(file = path) - pkg_name <- pkg_desc$get_field("Package") - pkg_url_glue <- "" - pkg_url <- pkg_desc$get_urls() - if (length(pkg_url)) { - pkg_url_glue <- glue::glue( - " ({pkg_url[[1]]})" - ) - } - return( - glue::glue("{pkg_name}{pkg_url_glue}") - ) -} diff --git a/R/generate_pkg_agent.R b/R/generate_pkg_agent.R new file mode 100644 index 0000000..6afdb79 --- /dev/null +++ b/R/generate_pkg_agent.R @@ -0,0 +1,26 @@ +#' Create a user agent for the active package +#' +#' @param path The path to the DESCRIPTION file, or to a directory within a +#' package. +#' +#' @return A string with the name of the package and (if available) the first +#' URL associated with the package. +#' +#' @export +generate_pkg_agent <- function(path = ".") { + if (!fs::is_dir(path) && fs::path_file(path) != "DESCRIPTION") { + path <- fs::path_dir(path) # nocov + } + pkg_desc <- desc::desc(file = path) + pkg_name <- pkg_desc$get_field("Package") + pkg_url_glue <- "" + pkg_url <- pkg_desc$get_urls() + if (length(pkg_url)) { + pkg_url_glue <- glue::glue( + " ({pkg_url[[1]]})" + ) + } + return( + glue::glue("{pkg_name}{pkg_url_glue}") + ) +} diff --git a/man/generate_pkg.Rd b/man/generate_pkg.Rd index 947ed3e..004172f 100644 --- a/man/generate_pkg.Rd +++ b/man/generate_pkg.Rd @@ -6,7 +6,7 @@ \usage{ generate_pkg( config_file = "_beekeeper.yml", - pkg_agent = pkg_agent(fs::path_dir(config_file)) + pkg_agent = generate_pkg_agent(config_file) ) } \arguments{ diff --git a/man/pkg_agent.Rd b/man/generate_pkg_agent.Rd similarity index 72% rename from man/pkg_agent.Rd rename to man/generate_pkg_agent.Rd index 1791d24..e0560cb 100644 --- a/man/pkg_agent.Rd +++ b/man/generate_pkg_agent.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/generate.R -\name{pkg_agent} -\alias{pkg_agent} +% Please edit documentation in R/generate_pkg_agent.R +\name{generate_pkg_agent} +\alias{generate_pkg_agent} \title{Create a user agent for the active package} \usage{ -pkg_agent(path = ".") +generate_pkg_agent(path = ".") } \arguments{ \item{path}{The path to the DESCRIPTION file, or to a directory within a diff --git a/tests/testthat/test-generate.R b/tests/testthat/test-generate.R index 49ac656..721d62b 100644 --- a/tests/testthat/test-generate.R +++ b/tests/testthat/test-generate.R @@ -18,10 +18,3 @@ test_that("Applying a 1-server config generates the expected R files.", { "nectar" ) }) - -test_that("pkg_agent() generates package agents", { - expect_identical( - pkg_agent(test_path("_fixtures", "DESCRIPTION")), - "beekeeper (https://jonthegeek.github.io/beekeeper/)" - ) -}) diff --git a/tests/testthat/test-generate_pkg_agent.R b/tests/testthat/test-generate_pkg_agent.R new file mode 100644 index 0000000..dddc057 --- /dev/null +++ b/tests/testthat/test-generate_pkg_agent.R @@ -0,0 +1,6 @@ +test_that("generate_pkg_agent() generates package agents", { + expect_identical( + generate_pkg_agent(test_path("_fixtures", "DESCRIPTION")), + "beekeeper (https://jonthegeek.github.io/beekeeper/)" + ) +})