Skip to content

Commit

Permalink
Get name from global options
Browse files Browse the repository at this point in the history
Fixes r-lib#79
  • Loading branch information
hadley committed Oct 12, 2017
1 parent e49039b commit 3ecd035
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
32 changes: 28 additions & 4 deletions R/license.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
#'
#' @name licenses
#' @param name Name of the copyright holder or holders. Separate multiple
#' individuals with `;`.
#' individuals with `;`. You can supply a global default with
#' `options(usethis.full_name = "My name")`.
#' @inheritParams use_template
#' @aliases NULL
#' @md
NULL

#' @rdname licenses
#' @export
use_mit_license <- function(name,
use_mit_license <- function(name = find_name(),
base_path = ".") {

force(name)
Expand All @@ -51,7 +52,7 @@ use_mit_license <- function(name,

#' @rdname licenses
#' @export
use_gpl3_license <- function(name, base_path = ".") {
use_gpl3_license <- function(name = find_name(), base_path = ".") {
force(name)

use_description_field(
Expand All @@ -64,7 +65,7 @@ use_gpl3_license <- function(name, base_path = ".") {

#' @rdname licenses
#' @export
use_apl2_license <- function(name, base_path = ".") {
use_apl2_license <- function(name = find_name(), base_path = ".") {
force(name)

use_description_field(
Expand Down Expand Up @@ -95,3 +96,26 @@ license_data <- function(name, base_path = ".") {
project = project_name(base_path)
)
}


find_name <- function(name = NULL) {
if (!is.null(name)) {
return(name)
}

name <- getOption("devtools.name")
if (!is.null(name)) {
return(name)
}

name <- getOption("usethis.full_name")
if (!is.null(name)) {
return(name)
}

stop(
"`name` argument is missing.\n",
'Set it globally with `options(usethis.full_name = "My name").',
call. = FALSE
)
}
9 changes: 5 additions & 4 deletions man/licenses.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3ecd035

Please sign in to comment.