Clii - Easily build a cli app

Overview

Clii

Easily build a cli app.

Write some functions, jsdoc it, clii automatically turns it into a cli.

examples/demo.mjs

Quick Start

Install clii package.

npm i clii
yarn add clii

Write some js code

/**
 * A simple task
 * @param {Object} options
 * @param {number} options.num - Num variable
 * @param {("prod"|"dev"|"stage")} options.mode - Build mode
 */
export async function task(options) {
  console.log(options);
}

Add follow content to your file.

import clii from "clii";

clii(import.meta.url);

All done.

What an easy way to build the cli app.

Try it in your terminal

$ node index.mjs task1 -h
index.mjs task1 [options]

Options:
      --version  Show version number                                   [boolean]
  -f, --file     Specific clii file                                     [string]
  -w, --workdir  Specific working directory                             [string]
      --num      Num variable                                           [number]
      --mode     Build mode           [string] [choices: "prod", "dev", "stage"]
  -h, --help     Show help                                             [boolean]

$ node index.mjs task --num 3 --mode prod
{ num: 3, mode: 'prod' }

clii parse your ast js module file, generate cli interface according comments and exports semantics.

Export variable settings will be parsed as global options.

export const settings = {
  // Default port number
  port: 3000,
};
Options:
      --port     Default port number                    [number] [default: 3000]

Export function cmd2 will be parsed as subcommand. It's parameters will be parsed as subcommand's options.

Commands:
  demo.mjs cmd2 
   
     [options]  Another command

   

The export default function will be th default command.

Cli Tool

Since clii can run js functions directly from cli, it can be used as task runner / build tool.

By default, clii looks for file cliifile.mjs in the current directory and upwards, so you can invoke it from any subdirectory of your project.

You can organize your project scripts with cliifile.mjs to provide unified entrypoint and help information.

export function lint() {}
/**
 * Build
 * @param {Object} options
 * @param {boolean} options.prod
 */
export function build(options) {
  lint();
}
$ clii
Usage: clii 
   
     [options]

Commands:
  clii lint
  clii build [options]  Build

Options:
      --version  Show version number                                   [boolean]
  -f, --file     Specific clii file                                     [string]
  -w, --workdir  Specific working directory                             [string]
  -h, --help     Show help                                             [boolean]

$ clii build
$ clii lint

   

License

Apache-2.0

You might also like...

:notes: Control iTunes via CLI

:notes: Control iTunes via CLI

itunes-remote Control iTunes via your terminal 🎶 Using JXA via osascript via Node.js. Requirements Node.js (v0.12.7 or greater) Mac OS X (Yosemite 10

Nov 19, 2022

A CLI for peer-to-peer file sharing using the Hypercore Protocol.

A CLI for peer-to-peer file sharing using the Hypercore Protocol.

A CLI for peer-to-peer file sharing (and more) using the Hypercore Protocol.

Dec 30, 2022

Node.js Open CLI Framework. Built with 💜 by Heroku.

Node.js Open CLI Framework. Built with 💜 by Heroku.

oclif: Node.JS Open CLI Framework 🗒 Description 🚀 Getting Started Tutorial ✨ Features 📌 Requirements 🌈 CLI Types 🏗 Usage 📚 Examples 🔨 Commands

Jan 4, 2023

Git commit CLI

commitme Based on this gist by @gustavopch Installation You can install this on your package using npm i -D commitme or run it once using npx commitme

Jun 6, 2021

An extension geared towards Spotify users with larger libraries; view all your playlists that contain a specific song with the click of a button. Designed for Spicetify (https://github.com/khanhas/spicetify-cli)

An extension geared towards Spotify users with larger libraries; view all your playlists that contain a specific song with the click of a button. Designed for Spicetify (https://github.com/khanhas/spicetify-cli)

ViewPlaylistsWithSong An extension developed for Spicetify that allows you to view all the playlists in your library that contain a certain song. Idea

Dec 13, 2022

HMSC (How Much Stuffs CLI) analyst for your files and folders

HMSC (How Much Stuffs CLI) analyst for your files and folders

HMSC 🔰 About HMSC (How Much Stuffs CLI) analyst for your files and folders 📸 Screenshot 📓 Requirements Node.js NPM 🔌 Installation $ npm i -g hmsc

Jan 10, 2022

A C++ based command-line (CLI) program that lets you manage your tasks

A C++ based command-line (CLI) program that lets you manage your tasks

COMMAND LINE INTERFACE TODO APP a command-line (CLI) program that lets you manage your tasks. The specification for this project is written down as te

Dec 25, 2021

A CLI progam show teminal outputs as gradients.

A CLI progam show teminal outputs as gradients.

GRADIENT-TERMINAL A CLI progam to display teminal outputs as gradients. Requirements For Installation, you will only need Node.js. Install $ git clone

Jan 3, 2023
Owner
null
LinkFree CLI is a command line tool that helps you to create your LinkFree profile through CLI.

LinkFree CLI LinkFree CLI is a command line tool that helps you to create your LinkFree profile through CLI. Demo Using the CLI (Commands) Note First

Pradumna Saraf 32 Dec 26, 2022
NodeJS built CLI, allows to spell check in 14 languages, get Coleman-Liau Index and build hash Pyramids

Magic CLI ?? ?? NodeJS built CLI, allows to spell check in 14 languages, get Coleman-Liau Index and build hash Pyramids Installing Install dependencie

Lucas 3 Sep 27, 2022
Add stdin support to any CLI app that accepts file input

tmpin Add stdin support to any CLI app that accepts file input It pipes stdin to a temp file and spawns the chosen app with the temp file path as the

Sindre Sorhus 121 Oct 3, 2022
SFDX Plugin to set Email Deliverability Access Level for an org easily and quickly via command line interface

SFDX Plugin to set Email Deliverability Access Level for an org easily and quickly via command line interface

Max Goldfarb 11 Dec 16, 2022
Infinite Red's cutting edge React Native project boilerplate, along with a CLI, component/model generators, and more!

Ignite - the hottest React Native boilerplate Battle-tested React Native boilerplate The culmination of five years of constant React Native developmen

Infinite Red, Inc. 14.7k Dec 29, 2022
CLI tool for running Yeoman generators

yo What's Yeoman? Yeoman helps you to kickstart new projects, prescribing best practices and tools to help you stay productive. To do so, we provide a

Yeoman 3.6k Dec 30, 2022
Test your internet connection speed and ping using speedtest.net from the CLI

speed-test Test your internet connection speed and ping using speedtest.net from the CLI Install Ensure you have Node.js version 8+ installed. Then ru

Sindre Sorhus 3.8k Jan 7, 2023
Distributed, realtime CLI for live Node apps.

Vantage = CLI + SSH + REPL for your live node app. In one line: require("vantage")().listen(4000); What just happened? That's voodoo magic: show me th

dc 3.5k Dec 30, 2022
download torrents with node from the CLI

torrent Download torrents from the command line usage torrent <magnet link OR path to .torrent file> Download a torrent from a magnet link to torre

Max Ogden 619 Dec 26, 2022
:white_square_button: WhatsApp chat from commandline/console/cli using GoogleChrome puppeteer

Whatspup Use Whatsapp from commandline/console/cli using GoogleChrome puppeteer! ?? Features ✅ Send and receive messages ✅ Read Receipts ✅ Switch betw

Sarfraz Ahmed 343 Dec 1, 2022