Skip to content

Commit

Permalink
Merge pull request #170 from r-lib/feature/run
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi authored Jul 25, 2023
2 parents 9152bb8 + 355ef29 commit 2a8f006
Show file tree
Hide file tree
Showing 16 changed files with 837 additions and 6 deletions.
54 changes: 48 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ semver = "1.0.4"
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
serde_json = "1.0"
serde_yaml = "0.9"
sha2 = "0.9.8"
shellexpand = "2.1.0"
simple-error = "0.2.3"
Expand Down
2 changes: 2 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,14 @@ Run `rig` to see all commands and examples.

```
rig add -- install a new R version [alias: install]
rig available -- List R versions available to install.
rig default -- print or set default R version [alias: switch]
rig library -- manage package libraries [alias: lib] (experimental)
rig list -- list installed R versions [alias: ls]
rig resolve -- resolve a symbolic R version
rig rm -- remove R versions [aliases: del, delete, remove]
rig rstudio -- start RStudio with the specified R version
rig run -- Run R, an R script or an R project
rig sysreqs -- manage R-related system libraries and tools (experimental) (macOS)
rig system -- manage current installations
```
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,14 @@ Run `rig` to see all commands and examples.
### Command list:

rig add -- install a new R version [alias: install]
rig available -- List R versions available to install.
rig default -- print or set default R version [alias: switch]
rig library -- manage package libraries [alias: lib] (experimental)
rig list -- list installed R versions [alias: ls]
rig resolve -- resolve a symbolic R version
rig rm -- remove R versions [aliases: del, delete, remove]
rig rstudio -- start RStudio with the specified R version
rig run -- Run R, an R script or an R project
rig sysreqs -- manage R-related system libraries and tools (experimental) (macOS)
rig system -- manage current installations

Expand Down
91 changes: 91 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ pub fn rig_app() -> Command {
let _arch_x86_64: &'static str = "x86_64";
let _arch_arm64: &'static str = "arm64";
let mut _default_arch: &'static str = "";
let app_types = [
"api",
"shiny",
"quarto-shiny",
"rmd-shiny",
"quarto-static",
"rmd-static",
"static"
];

#[cfg(target_os = "macos")]
{
Expand Down Expand Up @@ -554,6 +563,87 @@ pub fn rig_app() -> Command {
rig = rig.subcommand(cmd_sysreqs);
}

let cmd_run = Command::new("run")
.about("Run R, an R script or an R project")
.long_about(HELP_RUN)
.arg(
Arg::new("r-version")
.help("R version to use")
.short('r')
.long("r-version")
.required(false)
)
.arg(
Arg::new("app-type")
.help("Explicitly specify app type to run")
.short('t')
.long("app-type")
.required(false)
.value_parser(app_types)
.conflicts_with("eval")
.conflicts_with("script")
)
.arg(
Arg::new("dry-run")
.help("Show the command, but do not run it")
.long("dry-run")
.required(false)
.action(clap::ArgAction::SetTrue)
)
.arg(
Arg::new("startup")
.help("Print R startup message")
.long("startup")
.action(clap::ArgAction::SetTrue)
.required(false)
)
.arg(
Arg::new("no-startup")
.help("Do not print R startup message")
.long("no-startup")
.action(clap::ArgAction::SetTrue)
.required(false)
.conflicts_with("startup")
)
.arg(
Arg::new("echo")
.help("Print input to R")
.long("echo")
.action(clap::ArgAction::SetTrue)
.required(false)
)
.arg(
Arg::new("no-echo")
.help("Do not print input to R")
.long("no-echo")
.action(clap::ArgAction::SetTrue)
.required(false)
.conflicts_with("echo")
)
.arg(
Arg::new("eval")
.help("R expression to evaluate")
.short('e')
.long("eval")
.num_args(1)
.required(false)
)
.arg(
Arg::new("script")
.help("R script file to run")
.short('f')
.long("script")
.num_args(1)
.required(false)
.conflicts_with("eval")
)
.arg(
Arg::new("command")
.help("R script or project to run, with parameters")
.required(false)
.action(clap::ArgAction::Append)
);

rig = rig.arg(
Arg::new("quiet")
.help("Suppress output (overrides `--verbose`)")
Expand Down Expand Up @@ -586,6 +676,7 @@ pub fn rig_app() -> Command {
.subcommand(cmd_rstudio)
.subcommand(cmd_library)
.subcommand(cmd_available)
.subcommand(cmd_run)
.after_help(HELP_EXAMPLES);

rig
Expand Down
27 changes: 27 additions & 0 deletions src/help-common.in
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,30 @@ const HELP_SYSTEM_LIB: &str = "
`rig add` runs `rig system create-lib`, so if you only use rig to
install R, then you do not need to run it manually.";

const HELP_RUN: &str = "
\x1b[4m\x1b[1mDescription:\x1b[22m\x1b[24m
Run R, an R script or an R project, using the selected R version.
All of these examples allow an `--r-version` argument, to use a specific
R version.
Start R:
rig run
Run an R script:
rig run -f <script-file>
Evaluate an R expression:
rig run -e <expression>
Run a script from a package (from its `exec` directory):
rig run <pkg>::<script>
Run an R app:
rig run <path-to-app>
Currently supported apps are:
- Plumber APIs,
- Shiny apps,
- Quarto dcouments embedding Shiny apps,
- Quarto documents,
- Rmd documents,
- Rmd documents embedding Shiny apps,
- Static web sites.";
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use tabular::*;
mod args;
use args::*;

mod scrun;
use scrun::*;

#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "macos")]
Expand Down Expand Up @@ -109,6 +112,7 @@ fn main__(args: &ArgMatches) -> Result<(), Box<dyn Error>> {
Some(("library", sub)) => sc_library(sub, args),
Some(("sysreqs", sub)) => sc_sysreqs(sub, args),
Some(("available", sub)) => sc_available(sub, args),
Some(("run", sub)) => sc_run(sub, args),
_ => Ok(()), // unreachable
}
}
Expand Down
Loading

0 comments on commit 2a8f006

Please sign in to comment.