Code generator to produce CLI from R packages

cmd

Create command line applications from R packages.

How it works It's a code generator that outputs Go code which produces a Command Line Application.

It's a bit ugly and unwieldy but it does the job.

Using the generated CLI requires an installation of R

Install

go get -u devOpifex/cmd
go install -u devOpifex/cmd@latest

Config

Create a config file called cmd.json at the root of your R package.

{
  "program": "rshiny",
  "package": "shiny",
  "description": "shiny from the command line",
  "install": "install.packages('shiny')",
  "commands": [
    {
      "name": "run",
      "short": "r",
      "description": "run the application",
      "function": "runApp",
      "arguments": [
        {
          "name": "dir",
          "short": "d",
          "description": "directory where the app.R is location",
          "type": "string",
          "required": false,
          "default": "."
        }
      ]
    }
  ]
}

Root

Specify the name of the program this is what users will call as root command in their shell. Indicate the package this CLI wraps.

In the example above we create a CLI for the shiny package and call the program rshiny, e.g.: rshiny -h will bring up the help.

Commands

List the commands you want to expose to the users of the CLIU, these map to functions from the package. The short is the short version of the command so one can use rshiny run or rshiny r: this will run shiny::runApp().

Arguments

List the arguments the function should take: these are currently passed unnamed so order matters

Type can be one of string, numeric, integer or, logical.

Above makes it such that we can call rshiny run -d="this/dir" or rshiny run --dir=/some/path

Install

Is used to generate the rshiny install command which installs the required R dependencies.

Generate

Once the config file created and cmd installed run cmd generate from the root of the package where the config file is located.

This creates a directory named after your program.

Move into the created directory (e.g.: cd rshiny in the example above) then run the folowing.

go mod init github.com/<username>/<repo>/<program>
go mod tidy

The first line will (in part) ensure you can work with go outside of your GOROOT, the second downloads dependencies if there are any (currently only cobra).

You should only need to run the above once. No need to repeat the process if you want to update your config and regenerate the code with cmd generate.

Then to build run the following.

go build

This should produce a program you can call from the command line. If you only need it on your own system you can just call go install.

By default go build builds for your system, you can easily build for other system with:

GOOS=linux go build
GOOS=windows go build
GOOS=darwin go build
Owner
Opifex
Data & Programming
Opifex
Similar Resources

(en|de)code urls from the CLI

hakurlencode (en|de)code urls from the CLI Installation go get github.com/hakluke/hakurlencode Usage Pipe into the tool with no options to encode, fo

Jun 9, 2022

The Code Templates for Basil CLI 🌿

Basil Templates 🌿 This repository includes code templates for miscellaneous programming languages and technologies. Basil CLI uses these templates fo

Dec 15, 2021

Show Languages In Code. A fast and lightweight CLI to generate stats on the languages inside your project

Show Languages In Code. A fast and lightweight CLI to generate stats on the languages inside your project

slic Show Languages In Code. Usage Run it with an -h flag to list all commands. -d flag can be used to specify the directory of search -i flag can be

Dec 25, 2021

Snippet CLI manger for quickly using code snippets without leaving the terminal

Snippet CLI manger for quickly using code snippets without leaving the terminal

SnipKit - Snippet CLI manager This repository is still work in progress! SnipKit aims to paste code snippets from your favorite snippet manager into y

Dec 27, 2022

Code and slides from the talk "A golang CLI to rule them all" at JavaZone 2021

A Golang CLI to rule them all This is a repo for the slides and the code that were showed at the presentation with the same title at the JavaZone conf

Sep 28, 2022

what-to-code.com CLI client

what-to-code.com CLI client

What CLI What to code CLI client About The Project This project allows you to view ideas from what-to-code.com from your terminal. You can also share

Oct 31, 2022

Elegant CLI wrapper for kubeseal CLI

Overview This is a wrapper CLI ofkubeseal CLI, specifically the raw mode. If you just need to encrypt your secret on RAW mode, this CLI will be the ea

Jan 8, 2022

CLI to run a docker image with R. CLI built using cobra library in go.

CLI  to run a docker image with R. CLI built using cobra library in go.

BlueBeak Installation Guide Task 1: Building the CLI The directory structure looks like Fastest process: 1)cd into bbtools 2)cd into bbtools/bin 3)I h

Dec 20, 2021

A wrapper of aliyun-cli subcommand alidns, run aliyun-cli in Declarative mode.

aliyun-dns A wrapper of aliyun-cli subcommand alidns, run aliyun-cli in Declarative mode. Installation Install aliyun-cli. Usage $ aliyun-dns -h A wra

Dec 21, 2021
Related tags
AI-powered code snippet generator using ChatGPT. Generate code in various languages based on natural language descriptions!

SnipForge - AI-Powered Code Snippet Generator SnipForge is a powerful command-line interface (CLI) tool that utilizes OpenAI's GPT technology to gener

May 5, 2023
:mag: Search the Go packages via command-line

GoSearch Search the Go packages for pkg.go.dev via command-line. It supports all search options in Search Help. Installation go get github.com/mingram

Jun 23, 2022
It is an easy and fast tool to install your packages with just one command.

Trouxa It is an easy and fast tool to install your packages with just one command. What means "Trouxa"? In portuguese, Trouxa means something like a "

Sep 29, 2022
Get Brew Packages to update, just like you've experienced from Ubuntu
Get Brew Packages to update, just like you've experienced from Ubuntu

Get the number of Brew Packages to update, just like you've experienced from Ubuntu BrewUpdate is a simple utility written in Go, notify you how many

Nov 6, 2021
This repository contains utility functions that do not make sense in other packages.

Installation go get github.com/IQ-tech/go-utils Executing code before process exits AtInterruption receives a function that will be called once befor

Dec 9, 2021
Gopkg - Search go.dev packages by keyword

gopkg Search go.dev packages by keyword Usage Install go install github.com/luck

Apr 6, 2022
Envopts - Provides a code generator for turning env structs into functional options

envopts Provides a code generator to turn structs annotated for the popular env

Jan 10, 2022
License-cli - simple LICENSE file generator

?? license-cli simple LICENSE file generator 2022-01-04.12-28-26.mp4 Install / U

Jun 2, 2022
This project is used to get familiar with GoLang cli apps, along with cobra generator.

SecretCTL SecretCTL About the project Status Getting started Layout Notes About the project This project is used to get familiar with GoLang cli apps,

Jan 11, 2022
Sloc, Cloc and Code: scc is a very fast accurate code counter with complexity calculations and COCOMO estimates written in pure Go
Sloc, Cloc and Code: scc is a very fast accurate code counter with complexity calculations and COCOMO estimates written in pure Go

Sloc Cloc and Code (scc) A tool similar to cloc, sloccount and tokei. For counting physical the lines of code, blank lines, comment lines, and physica

Jan 8, 2023