|
| 1 | +# nocov start |
| 2 | + |
| 3 | +git_links <- function() { |
| 4 | + rlang::check_installed("tibble") |
| 5 | + tibble::tribble( |
| 6 | + ~command , ~url , |
| 7 | + "checkout" , "https://libgit2.org/docs/reference/main/checkout/index.html" |
| 8 | + ) |
| 9 | +} |
| 10 | + |
| 11 | +#' @exportS3Method roxygen2::roxy_tag_parse |
| 12 | +roxy_tag_parse.roxy_tag_git <- function(x) { |
| 13 | + roxygen2::tag_words(x) |
| 14 | +} |
| 15 | + |
| 16 | +#' @exportS3Method roxygen2::roxy_tag_rd |
| 17 | +roxy_tag_rd.roxy_tag_git <- function(x, base_path, env) { |
| 18 | + roxygen2::rd_section("gitcommands", x$val) |
| 19 | +} |
| 20 | + |
| 21 | +#' @export |
| 22 | +format.rd_section_gitcommands <- function(x, ...) { |
| 23 | + paste0( |
| 24 | + "\\section{Related libgit2 documentation}{", |
| 25 | + present_git_link(x[["value"]]), |
| 26 | + ".}\n" |
| 27 | + ) |
| 28 | +} |
| 29 | + |
| 30 | +present_git_link <- function(value) { |
| 31 | + format_git_single_link <- function(x, git_links) { |
| 32 | + df <- git_links[git_links$command == x, ] |
| 33 | + if (nrow(df) == 0) { |
| 34 | + cli::cli_warn("Can't find libgit2 entry for {x}!") |
| 35 | + } |
| 36 | + sprintf("\\href{%s}{\\code{%s}}", df$url, df$command) |
| 37 | + } |
| 38 | + |
| 39 | + strings <- purrr::map_chr( |
| 40 | + unique(value), |
| 41 | + format_git_single_link, |
| 42 | + git_links = git_links() |
| 43 | + ) |
| 44 | + |
| 45 | + paste(strings, collapse = ", ") |
| 46 | +} |
| 47 | +# nocov end |
0 commit comments