Skip to content

Commit 072916a

Browse files
committed
Update NEWS and README
1 parent bb9dba4 commit 072916a

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Added support for short opts (#4, #5).
55
* New `install_pkg_cli_apps()` installs Rapps and R scripts
66
in a package's `exec/` directory on the users `PATH` (#7, #3).
7+
* Declaring `c()` or `list()` defaults now creates repeatable CLI options.
78

89
# Rapp 0.2.0
910

README.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ Rapp::install_pkg_cli_apps("Rapp")
6868

6969
On macOS and Linux, make your script executable (`chmod +x flip-coin.R`)
7070
and run it directly. On Windows, or if you prefer, call the front end
71-
explicitly: `Rapp flip-coin.R --n 3`.
71+
explicitly with `Rapp flip-coin.R --n 3`.
7272

7373
Application options and arguments work like this:
7474

7575
| Script declaration | CLI usage | Effect |
7676
| --- | --- | --- |
77-
| `foo <- NULL` | `APP <FOO>` | Positional argument with a default value |
77+
| `foo <- NULL` | `APP [FOO]` | Optional positional argument |
7878
| `foo <- TRUE` / `foo <- FALSE` | `APP --foo` / `APP --no-foo` | Boolean switch |
79-
| `foo <- 1`, `foo <- 1.5`, `foo <- "value"` | `APP --foo VALUE` | Single-value option |
80-
| `foo <- c()` / `foo <- list()` | `APP --foo value1 --foo value2` | Repeatable option that appends each value |
79+
| `foo <- 1`, `foo <- "default"` | `APP --foo VALUE` | Single-value option |
80+
| `foo <- c()` / `foo <- list()` | `APP --foo value1 --foo value2` | Repeatable option that appends each value (`c()` keeps strings, `list()` parses YAML/JSON) |
8181

8282
## Options
8383

@@ -94,7 +94,7 @@ becomes an option at the command line:
9494
flip-coin --n 1
9595
```
9696

97-
Option values passed from the command line are parsed as yaml/json, and
97+
Option values passed from the command line are parsed as YAML/JSON, and
9898
then coerced to the original R type. The following option value types
9999
are supported: int, float, string, and bool. Values can be supplied
100100
after the option, or as part of the option with `=`. The following two
@@ -134,16 +134,34 @@ Hash-pipe annotations are parsed as YAML values. Quote scalars such as
134134
interpretation.
135135

136136
Assigning `c()` or `list()` now declares a repeatable option. Each time
137-
the option is supplied, its value is appended in order. For example:
137+
the option is supplied, its value is appended in order. Use `c()` when
138+
you want to keep the exact strings provided on the command line, and
139+
`list()` when you want Rapp to opportunistically parse values as
140+
YAML/JSON (so you can receive integers, booleans, lists, etc). For
141+
example, a repeatable filter option that keeps raw strings:
138142

139143
``` r
144+
#| description: File name patterns to include (repeatable).
140145
pattern <- c()
141146
```
142147

143-
becomes:
148+
can be invoked as:
144149

145150
``` bash
146-
ls-r --pattern alpha --pattern ".*\\.txt$"
151+
list-files --pattern '*.csv' --pattern sales-*
152+
```
153+
154+
Or, to collect numeric limits and have them parsed back into integers:
155+
156+
``` r
157+
#| description: Score thresholds (parsed as numbers, repeatable).
158+
threshold <- list()
159+
```
160+
161+
which lets callers supply structured values:
162+
163+
``` bash
164+
report --threshold 5 --threshold '[10, 20, 30]'
147165
```
148166

149167
## Positional arguments
@@ -357,7 +375,7 @@ like on other platforms:
357375
flip-coin --n 3
358376
```
359377

360-
Because windows does not natively support shebangs, to invoke an Rapp
378+
Because Windows does not natively support shebangs, to invoke an Rapp
361379
developed outside an R package, you'll need to invoke the `Rapp`
362380
front-end directly (after calling `Rapp::install_pkg_cli_apps("Rapp")`):
363381

0 commit comments

Comments
 (0)