1.0.0 • Published 8 years ago

cmdx v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

NOT READY FOR USE!!!!!!!!

cmdx

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