Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.
/ cmdx Public archive

Command Line Expressions - Construct Node.js CLI's with Ease!

Notifications You must be signed in to change notification settings

adamjeffries/cmdx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ARCHIVED / DEPRECATED

cmdx

Construct Node.js CLI's with ease, inspired by Regular Expression Syntax.

Tutorial

  1. Create cli.js and define a basic command:
#!/usr/bin/env node

const cmdx = require("cmdx");

const args = cmdx
  .usage("<Number:a> <op> <Number:b> [--floor, --round]?")
  .arg("op", {values: ["+", "-", "/", "*"]})
  .parse(process.argv);
  
if (!args) return console.log("Unrecognized Command");  
  
let value, a = args.a, b = args.b;
switch (args.op) {
  case "+": value = a + b; break;
  case "-": value = a - b; break;
  case "*": value = a * b; break;
  case "/": value = a / b; break;
  default: value = 0;
}
if (args["--floor"]) value = Math.floor(value);
if (args["--round"]) value = Math.round(value);
console.log(`${a} ${op} ${b} = ${value}`);  
  1. Create package.json
{
  "bin": {
    "math": "./cli.js"
  }
}
  1. Install globally for use in your terminal
npm install -g
  1. Run the math command
> math 1 + notanumber
Unrecognized Command

> math 1.2 + 2.3
3.5

> math 1.2 * 2.3 --floor
2

About

Command Line Expressions - Construct Node.js CLI's with Ease!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published