r-lib / cli

Tools for making beautiful & useful command line interfaces
https://cli.r-lib.org/
Other
644 stars 70 forks source link

Provide helper for making reproducible output #700

Open hadley opened 3 months ago

hadley commented 3 months ago

e.g. in testthat::local_reproducible_output() I have

  withr::local_options(
    crayon.enabled = crayon,
    cli.hyperlink = hyperlinks,
    cli.hyperlink_run = hyperlinks,
    cli.hyperlink_help = hyperlinks,
    cli.hyperlink_vignette = hyperlinks,
    cli.dynamic = FALSE,
    cli.unicode = unicode,
    cli.condition_width = Inf,
    cli.num_colors = if (crayon) 8L else 1L,
    useFancyQuotes = FALSE,
    lifecycle_verbosity = "warning",
    OutDec = ".",
    rlang_interactive = FALSE,
    max.print = 99999,
    .local_envir = .env,
  )
  withr::local_envvar(
    RSTUDIO = if (rstudio) 1 else NA,
    RSTUDIO_SESSION_PID = if (rstudio) Sys.getpid() else NA,
    RSTUDIO_CHILD_PROCESS_PANE = if (rstudio) "build" else NA,
    RSTUDIO_CLI_HYPERLINKS = if (rstudio) 1 else NA,
    .local_envir = .env
  )

These have grown organically over time, so I suspect some are no longer useful, but it really feels like it would be easier if cli exposed some API to control the options that are most likely to cause its output to vary.