Skip to content

Latest commit

 

History

History
88 lines (65 loc) · 2.09 KB

cli_readme.md

File metadata and controls

88 lines (65 loc) · 2.09 KB

Overview

cli.mjs provides essential tools for JS CLI apps. Features:

  • Platform-agnostic OS args.
    • Works in Deno.
    • Works in Node.
    • Always empty in browsers.
  • Platform-agnostic console clearing.
  • Parsing of CLI flags.
  • Tiny, no external dependencies.

TOC

Usage

CLI args:

import * as cl from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.53/cli.mjs'

const cli = cl.Flag.os()

console.log(...cli.entries())
console.log(...cli.args)

Console clearing:

import * as cl from 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.53/cli.mjs'

cl.emptty()

Clearing the console only once, before running your code:

import 'https://cdn.jsdelivr.net/npm/@mitranim/js@0.1.53/cli_emptty.mjs'

API

class Flag

Links: source; test/example.

Parser for CLI args. Features:

  • Supports flags prefixed with -, --.
  • Supports = pairs.
  • Separates flags from unflagged args.
  • Parses flags into a map.
  • Stores remaining args as an array.
  • On-demand parsing of booleans and numbers.
const cli = cl.Flag.os()
const args = cli.args
const watch = cli.boolOpt(`w`)

Undocumented

The following APIs are exported but undocumented. Check cli.mjs.