All Projects → d4rkr00t → Opaline

d4rkr00t / Opaline

NextJS for CLI tools

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Opaline

Typin
Declarative framework for interactive CLI applications
Stars: ✭ 126 (+50%)
Mutual labels:  command-line-tool, cli, command-line, framework
Terjira
Terjira is a very interactive and easy to use CLI tool for Jira.
Stars: ✭ 713 (+748.81%)
Mutual labels:  command-line-tool, cli, command-line
Swiftline
Swiftline is a set of tools to help you create command line applications.
Stars: ✭ 1,156 (+1276.19%)
Mutual labels:  cli, command-line, framework
Nexmo Cli
Nexmo CLI (Command Line Interface)
Stars: ✭ 73 (-13.1%)
Mutual labels:  command-line-tool, cli, command-line
Pyinquirer
A Python module for common interactive command line user interfaces
Stars: ✭ 1,151 (+1270.24%)
Mutual labels:  command-line-tool, cli, command-line
Swiftcli
A powerful framework for developing CLIs in Swift
Stars: ✭ 673 (+701.19%)
Mutual labels:  cli, command-line, framework
Github Files Fetcher
Download a specific folder or file from a GitHub repo through command line
Stars: ✭ 73 (-13.1%)
Mutual labels:  command-line-tool, cli, command-line
Cli
A command-line interface for Hetzner Cloud
Stars: ✭ 542 (+545.24%)
Mutual labels:  command-line-tool, cli, command-line
Ecsctl
Command-line tool for managing AWS Elastic Container Service and Projects to run on it.
Stars: ✭ 15 (-82.14%)
Mutual labels:  command-line-tool, cli, command-line
Pilgo
Configuration-based dotfiles manager
Stars: ✭ 78 (-7.14%)
Mutual labels:  cli, command-line, framework
Cac
Simple yet powerful framework for building command-line apps.
Stars: ✭ 1,017 (+1110.71%)
Mutual labels:  cli, command-line, framework
Guaka
The smartest and most beautiful (POSIX compliant) Command line framework for Swift 🤖
Stars: ✭ 1,145 (+1263.1%)
Mutual labels:  cli, command-line, framework
Papis
Powerful and highly extensible command-line based document and bibliography manager.
Stars: ✭ 636 (+657.14%)
Mutual labels:  command-line-tool, cli, command-line
Ripgrep
ripgrep recursively searches directories for a regex pattern while respecting your gitignore
Stars: ✭ 28,564 (+33904.76%)
Mutual labels:  command-line-tool, cli, command-line
Sultan
Sultan: Command and Rule over your Shell
Stars: ✭ 625 (+644.05%)
Mutual labels:  command-line-tool, cli, command-line
Aruba
Test command-line applications with Cucumber-Ruby, RSpec or Minitest. The most up to date documentation can be found on Cucumber.Pro (https://app.cucumber.pro/projects/aruba)
Stars: ✭ 900 (+971.43%)
Mutual labels:  cli, command-line, framework
Rff Cli Example
An example of how to use 🏁 React Final Form in a CLI application with Ink
Stars: ✭ 55 (-34.52%)
Mutual labels:  command-line-tool, cli, command-line
Node.cli Progress
⌛️ easy to use progress-bar for command-line/terminal applications
Stars: ✭ 466 (+454.76%)
Mutual labels:  command-line-tool, cli, command-line
Cbt
CBT - fun, fast, intuitive, compositional, statically checked builds written in Scala
Stars: ✭ 489 (+482.14%)
Mutual labels:  command-line-tool, cli, command-line
Laminas Cli
Console command runner, exposing commands written in Laminas MVC and Mezzio components and applications
Stars: ✭ 25 (-70.24%)
Mutual labels:  command-line-tool, cli, command-line


opaline


Opaline – CLI Tools Framework


Node.js CI

Opaline — a CLI tools framework and compiler. It draws inspiration from NextJS(and similar projects) and provides a quick, convention based, way of creating CLI tools.

  1. It looks for files in ./commands folder and treats them as commands for a CLI:

    • commands
      └── build.ts
      
      # Means it can be run as following:
      λ cli build
      
  2. Command file must export a function (can be async function too):

    • export default function myCommand() {}
      // or
      module.exports = async function myCommand() {};
      
  3. Uses JSDoc to describe parameters and documentation for a CLI. Read more on supported JSDoc syntax and how to use it here.

Table of Contents

Usage

Use a generator to bootstrap an Opaline based CLI:

λ npx @opaline/core create app
λ cd app
λ npm install

Compile the CLI:

λ npm run build
λ npm run dev # for dev mode with watch and auto linking

Creating Commands

By default generator creates commands/index.js file, which is a default command, and can be run without specifying a command name:

λ cli --param1 20

But if required there might be multiple commands in one CLI. In order to do that, we just need to create another file in ./commands folder (or rename index.js, it's not required to have a default command):

// ./commands/build.js

export default function build() {
  console.log("hello build!");
}

Adding Command Parameters and Documentation

Opaline uses JSDoc to define parameters and documentation for a command.

Using unnamed arguments

Opaline can pass all non-flag arguments to a command, for this command needs to define an $inputs argument in the JSDoc as shown below:

// ./commands/build.js
/**
 * Description of a command is just a comment above the command's function.
 * Params are described as JSDoc params:
 *
 * @param {Array<string>} $inputs Any non-flag arguments are passed here
 */
export default function build($inputs) {
  console.log(`hello ${name}, language ${lang}`);
}

It's also possible to define named (flag) arguments:

// ./commands/build.js

/**
 * Description of a command is just a comment above the command's function.
 * Params are described as JSDoc params:
 *
 * @param {Array<string>} $input Any non-flag arguments are passed here
 * @param {string} name Name of an app to build
 * @param {string} [lang="TypeScript"] A parameter with default value
 */
export default function build($inputs, name, lang) {
  console.log(`hello ${name}, language ${lang}`);
}

Help will be generated for both default and this new command:

λ examples-for-docs --help # help for the whole cli, with list of commands

VERSION
  examples-for-docs/0.0.0

USAGE
  examples-for-docs inputs --param1 10 --param2 20

COMMANDS
  build     Description of a command is just a comment above the command's function. Params are described as JSDoc params:

> NOTE: To view the usage information for a specific command, run 'examples-for-docs [COMMAND] --help'

OPTIONS
  --param1      Some parameter for a CLI with a default value [number] [default: 20]
  --param2      Some parameter for a CLI [string]
  --help        Output usage information
  --version     Output the version number




λ examples-for-docs build --help # help for a subcommand

Description of a command is just a comment above the command's function. Params are described as JSDoc params:

OPTIONS
  --name     Name of an app to build [string]
  --lang     A parameter with default value [string] [default: "TypeScript"]

JSDoc

Opaline uses JSDoc to describe command's parameters and documentation.

Supported JSDoc Tags

Tag Description
@paramhttps://jsdoc.app/tags-param.html Supports primitive types: string, number, boolean. And arrays of strings string[]
@example Note: only one line examples: @example {cliName} --params 10

Extra JSDoc Tags

Tag Description
@param $inputs Indicates that command receives unnamed arguments
@usage Similar to example, but outlines the main example on how to use a CLI command. @usage {cliName} build
@short Defines an alias (shortcut) for a parameter. @short name=n
{cliName} A variable that will be replaced by the name of a CLI tool described in package.json. Supported by @usage and @example

package.json

Opaline gets multiple things from a package.json file, to even more reduce configuration:

package.json#bin

https://docs.npmjs.com/files/package.json#bin

There are 2 way of using the bin field in package.json:

// 1
{
  "name": "cli-name",
  "bin": "./cli/cli.js"
}

// 2
{
  "name": "cli-name",
  "bin": {
    "cli-name": "./cli/cli.js"
  }
}

Opaline supports both of them. And uses those fields in a following way:

  1. Path to a CLI file – For both cases the file path is used as an output target for a CLI entry point, and will be automatically created by Opaline, no need to manually create it.
  2. Name of a CLI – For [1] the name will be package.json#name, if you need to have a different name than the name of a package, use an option 2. Name is used as {cliName} in JSDoc and also when linking packages in dev mode. Which makes them accessible globally, by this name:
    • cli-name [COMMAND]

package.json#description

Used as main description for a CLI tool.

Examples

Tools built with Opaline:

Screenshots

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].