-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add print method for scan_deps() result
- Loading branch information
1 parent
d967c1b
commit c986c2e
Showing
5 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#' @export | ||
|
||
format.pkg_scan_deps <- function(x, ...) { | ||
labels <- c( | ||
prod = "Dependencies", | ||
test = "Test dependencies", | ||
dev = "Development dependencies", | ||
# TODO: generic label for others | ||
NULL | ||
) | ||
lns <- lapply(seq_along(labels), function(i) { | ||
deps <- x[x$type == names(labels)[i], , drop = FALSE] | ||
if (nrow(deps) == 0) return(NULL) | ||
fls <- tapply(deps$path, deps$package, "c", simplify = FALSE) | ||
fls[] <- lapply(fls, unique) | ||
fls <- vcapply(fls, paste, collapse = ", ") | ||
pkg <- format(names(fls)) | ||
flsw <- cli::console_width() - nchar(pkg[1]) - 5 | ||
c( | ||
"", cli::col_yellow(paste0(labels[i], ":")), | ||
paste0( | ||
cli::col_grey("+ "), | ||
cli::col_blue(pkg), | ||
cli::col_grey(" @ "), | ||
cli::col_silver(cli::ansi_strtrim(fls, flsw)) | ||
) | ||
) | ||
}) | ||
|
||
unlist(lns) | ||
} | ||
|
||
#' @export | ||
|
||
print.pkg_scan_deps <- function(x, ...) { | ||
writeLines(format(x, ...)) | ||
invisible(x) | ||
} | ||
|
||
#' @export | ||
|
||
`[.pkg_scan_deps` <- function (x, i, j, drop = FALSE) { | ||
class(x) <- setdiff(class(x), "pkg_scan_deps") | ||
NextMethod("[") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters