Giter VIP home page Giter VIP logo

js-fire's Introduction

js-fire CircleCI

A javascript implementation of google/python-fire

js-fire is a library for automatically generating command line interfaces (CLIs) from most js objects.

  • js Fire is a simple way to create a CLI in js.
  • js Fire helps with exploring existing code or turning other people's code into a CLI.
  • js Fire makes transitioning between Bash and js easier.

Installation

yarn add js-fire
npm install js-fire

Basic Usage

You can call Fire on any functions and objects:

Here's an example of calling Fire on a object, you can infinitely nest objects to create subcommands.

const fire = require('js-fire')

const calculator = {
  double: number => {
    // I double things
    return 2 * number
  },
  add: (n1 = Math.PI, n2) => {
    return n1 + n2
  },
  misc: {
    year: () => '1999',
    brand: () => 'casio',
    hello: name => `hello ${name}`,
  },
}

fire(calculator)

Then, from the command line, you can run:

node calculator.js double --number=15  # 30
node calculator.js misc hello hobochild  # 'hi hobochild'

Automactic --help command.

node calculator.js --help

USAGE:
	node object.js

COMMANDS:

	half  --number=<number>
	double  --number=<number>
	add  --n1=3.141592653589793  --n2=<n2>

	misc
		year
		brand
		hello  --name=<name>

Automactic --interactive mode:

asciicast

For additional examples, see /examples.

js-fire's People

Contributors

dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.