Skip to content

Commit 48f3d22

Browse files
authored
Merge pull request #84 from jmbarbone/83-ca-asis
Deprecates `command_args(string =)`
2 parents 5a92c4b + 3e381e0 commit 48f3d22

19 files changed

Lines changed: 232 additions & 108 deletions

.github/workflows/R-CMD-check.yaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
22
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3+
#
4+
# NOTE: This workflow is overkill for most R packages and
5+
# check-standard.yaml is likely a better choice.
6+
# usethis::use_github_action("check-standard") will install it.
37
on:
48
push:
59
branches: [main, master]
@@ -21,24 +25,26 @@ jobs:
2125
config:
2226
- {os: macos-latest, r: 'release'}
2327
- {os: windows-latest, r: 'release'}
24-
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
25-
- {os: ubuntu-latest, r: 'release'}
26-
- {os: ubuntu-latest, r: 'oldrel-1'}
28+
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
29+
- {os: ubuntu-latest, r: 'release'}
30+
- {os: ubuntu-latest, r: 'oldrel-1'}
31+
- {os: ubuntu-latest, r: 'oldrel-2'}
32+
- {os: ubuntu-latest, r: 'oldrel-3'}
33+
- {os: ubuntu-latest, r: 'oldrel-4'}
2734

2835
env:
2936
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
3037
R_KEEP_PKG_SOURCE: yes
3138

3239
steps:
33-
- uses: actions/checkout@v4
40+
- uses: actions/checkout@v6
3441

3542
- uses: r-lib/actions/setup-pandoc@v2
3643

3744
- uses: r-lib/actions/setup-r@v2
3845
with:
3946
r-version: ${{ matrix.config.r }}
4047
http-user-agent: ${{ matrix.config.http-user-agent }}
41-
use-public-rspm: true
4248

4349
- uses: r-lib/actions/setup-r-dependencies@v2
4450
with:

.github/workflows/lint.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ jobs:
1515
env:
1616
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
1717
steps:
18-
- uses: actions/checkout@v4
18+
- uses: actions/checkout@v6
1919

2020
- uses: r-lib/actions/setup-r@v2
21-
with:
22-
use-public-rspm: true
2321

2422
- uses: r-lib/actions/setup-r-dependencies@v2
2523
with:

.github/workflows/pkgdown.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ jobs:
2323
permissions:
2424
contents: write
2525
steps:
26-
- uses: actions/checkout@v4
26+
- uses: actions/checkout@v6
2727

2828
- uses: r-lib/actions/setup-pandoc@v2
2929

3030
- uses: r-lib/actions/setup-r@v2
31-
with:
32-
use-public-rspm: true
3331

3432
- uses: r-lib/actions/setup-r-dependencies@v2
3533
with:
@@ -42,7 +40,7 @@ jobs:
4240

4341
- name: Deploy to GitHub pages 🚀
4442
if: github.event_name != 'pull_request'
45-
uses: JamesIves/github-pages-deploy-action@v4.5.0
43+
uses: JamesIves/github-pages-deploy-action@d92aa235d04922e8f08b40ce78cc5442fcfbfa2f # v4.8.0
4644
with:
4745
clean: false
4846
branch: gh-pages
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
on:
22
pull_request:
33
branches: [main, master]
4+
paths-ignore:
5+
- '.github/**'
46

5-
name: version checks
7+
name: r-check-version.yaml
68

79
jobs:
810
check-r-version:
911
runs-on: ubuntu-latest
1012
env:
1113
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
1214
steps:
13-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v6
1416

1517
- uses: r-lib/actions/setup-r@v2
16-
with:
17-
use-public-rspm: true
1818

1919
- uses: r-lib/actions/setup-r-dependencies@v2
2020
with:
21-
packages: any::gh, any::fuj
22-
pandoc-install: false
21+
packages: |
22+
any::gh
23+
any::fuj
24+
any::scribe
25+
install-pandoc: false
2326

2427
- uses: jmbarbone/actions/r-check-version@main
2528
with:
26-
ignore-dev-version: true
29+
ignore-dev-version: false

.github/workflows/test-coverage.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ jobs:
1616
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
1717

1818
steps:
19-
- uses: actions/checkout@v4
19+
- uses: actions/checkout@v6
2020

2121
- uses: r-lib/actions/setup-r@v2
22-
with:
23-
use-public-rspm: true
2422

2523
- uses: r-lib/actions/setup-r-dependencies@v2
2624
with:
@@ -38,7 +36,7 @@ jobs:
3836
covr::to_cobertura(cov)
3937
shell: Rscript {0}
4038

41-
- uses: codecov/codecov-action@v5
39+
- uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7
4240
with:
4341
# Fail if error if not on PR, or if on PR and token is given
4442
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
@@ -56,7 +54,7 @@ jobs:
5654

5755
- name: Upload test results
5856
if: failure()
59-
uses: actions/upload-artifact@v4
57+
uses: actions/upload-artifact@v7
6058
with:
6159
name: coverage-test-failures
6260
path: ${{ runner.temp }}/package

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: scribe
22
Title: Command Argument Parsing
3-
Version: 0.3.0.9004
3+
Version: 0.3.0.9005
44
Authors@R:
55
person(
66
given = "Jordan Mark",
@@ -23,6 +23,7 @@ Imports:
2323
utils
2424
Suggests:
2525
covr,
26+
fuj,
2627
knitr,
2728
rmarkdown,
2829
spelling,
@@ -33,4 +34,5 @@ VignetteBuilder: knitr
3334
URL: https://jmbarbone.github.io/scribe/, https://github.com/jmbarbone/scribe
3435
BugReports: https://github.com/jmbarbone/scribe/issues
3536
Config/testthat/parallel: true
37+
Config/testthat/start-first: scripts, class-command-args
3638
Config/roxygen2/version: 8.0.0

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ These are not meant to be user accessible.
1717
- `arg$show()` now prints values of class `"scribe_empty_value"` as `<empty>`
1818
- `arg$add_argument()` correctly passes all method arguments [#78](https://github.com/jmbarbone/scribe/issues/78)
1919
- `ca$parse()` correctly deals with new arguments that nave the same _name_ as ones in `included` [#80](https://github.com/jmbarbone/scribe/issues/80)
20-
- internal documentation updates
20+
- `command_args(string=)` is now deprecated; pass strings in with `I()` instead (e.g., `command_args(I("-a 1 -b 2"))`) [#83](https://github.com/jmbarbone/scribe/issues/83)
21+
- internal testing fix for `scribe_version()`
2122

2223
# scribe 0.3.0
2324

R/command-args.R

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,39 @@
22
#'
33
#' Make a new [scribeCommandArgs] object
44
#'
5-
#' @param x,string Command line arguments; see [base::commandArgs()] for
6-
#' default. At least one parameter has to be `NULL`. When `string` is
7-
#' `NULL`, `x` is used, which defaults to `commandArgs(trailingOnly = TRUE)`.
8-
#' Otherwise the value of `x` is converted to a `character`. If `string` is
9-
#' not `NULL`, [scan()] will be used to split the value into a `character`
10-
#' vector.
5+
#' @param x Command line arguments as a character vector. Use `I()` to pass a
6+
#' single (combined) string of arguments.
117
#' @param include Special default arguments to included. See `$initialize()` in
128
#' [scribeCommandArgs] for more details.
139
#' @param super When `TRUE` the [scribeCommandArgs] object will be initialized
1410
#' with standard _super_ arguments (e.g., `---help`, `---version`)
11+
#' @param string Deprecated. Use `command_args(I())` to pass a single string of
12+
#' arguments.
1513
#' @examples
1614
#' command_args()
1715
#' command_args(c("-a", 1, "-b", 2))
18-
#' command_args(string = "-a 1 -b 2")
16+
#' command_args(I("-a 1 -b 2"))
1917
#' @returns A [scribeCommandArgs] object
2018
#' @family scribe
2119
#' @export
2220
command_args <- function(
23-
x = NULL,
21+
x = commandArgs(trailingOnly = TRUE),
2422
include = getOption("scribe.include", c("help", "version", NA_character_)),
25-
string = NULL,
26-
super = include
23+
super = include,
24+
string
2725
) {
28-
if (is.null(string)) {
29-
if (is.null(x)) {
30-
x <- commandArgs(trailingOnly = TRUE)
31-
}
32-
x <- as.character(x)
33-
} else {
34-
if (!is.null(x)) {
35-
stop("'string' and 'x' cannot both be set", call. = FALSE)
36-
}
26+
if (!missing(string)) {
27+
.Deprecated(
28+
msg = sprintf(
29+
"command_args(string=) is deprecated. Use command_args(I(\"%s\")) instead.", # nolint: line_length_linter.
30+
string
31+
)
32+
)
33+
x <- I(string)
34+
}
3735

38-
string <- as.character(string)
39-
x <- scan(text = string, what = "character", quiet = TRUE)
36+
if (inherits(x, "AsIs")) {
37+
x <- scan(text = as.character(x), what = character(), quiet = TRUE)
4038
}
4139

4240
scribeCommandArgs(input = x, include = include, super = super)

R/scribe-package.R

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,24 @@ NULL
1919
op.scribe <- list(
2020
scribe.flag.no = TRUE,
2121
scribe.interactive = NULL,
22-
scribe.include = c("help", "version")
22+
scribe.include = c("help", "version"),
23+
scribe.lib_check = FALSE
2324
)
2425

25-
.onAttach <- function(libname, pkgname) {
26-
options(op.scribe[setdiff(names(op.scribe), names(options()))])
26+
.onLoad <- function(libname, pkgname) {
27+
options(op.scribe[!names(op.scribe) %in% names(options())])
28+
if (isTRUE(getOption("scribe.lib_check"))) {
29+
tryCatch(
30+
find.package(
31+
"scribe",
32+
lib.loc = Sys.getenv("R_LIBS_SCRIBE", NA_character_)
33+
),
34+
packageNotFoundError = function(w) {
35+
packageStartupMessage(
36+
"The {scribe} package is not installed in the R_LIBS_SCRIBE path. ",
37+
"Please install {scribe} to use this package."
38+
)
39+
}
40+
)
41+
}
2742
}

R/super-arg.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,17 @@ scribe_version_super <- function() {
4343
)
4444
}
4545

46-
scribe_version <- function() {
47-
package_version(
48-
asNamespace("scribe")[[".__NAMESPACE__."]][["spec"]][["version"]]
49-
)
46+
scribe_version <- function(dev = TRUE) {
47+
expr <- substitute(asNamespace("scribe")[[".__NAMESPACE__."]][["spec"]][[
48+
"version"
49+
]])
50+
if (dev) {
51+
version <- eval(expr)
52+
} else {
53+
expr <- substitute(cat(expr, "\n", sep = ""), list(expr = expr))
54+
expr <- as.expression(expr)
55+
version <- rscript("-e", shQuote(expr, "sh"))
56+
}
57+
58+
package_version(version)
5059
}

0 commit comments

Comments
 (0)