Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/craigmulligan/js-fire
A javascript clone of google/python-fire 🔥
https://github.com/craigmulligan/js-fire
cli hacktoberfest javascript node nodejs python-fire
Last synced: 2 months ago
JSON representation
A javascript clone of google/python-fire 🔥
- Host: GitHub
- URL: https://github.com/craigmulligan/js-fire
- Owner: craigmulligan
- License: other
- Created: 2018-09-12T16:22:47.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-25T13:14:39.000Z (6 months ago)
- Last Synced: 2024-09-16T11:55:23.405Z (3 months ago)
- Topics: cli, hacktoberfest, javascript, node, nodejs, python-fire
- Language: JavaScript
- Homepage:
- Size: 542 KB
- Stars: 455
- Watchers: 6
- Forks: 10
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# js-fire [![Node.js CI](https://github.com/hobochild/js-fire/actions/workflows/node.js.yml/badge.svg)](https://github.com/hobochild/js-fire/actions/workflows/node.js.yml)
> A javascript implementation of [google/python-fire](https://github.com/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
```js-fire is exposed as both an [API](#api-usage) and a [CLI](#cli-usage).
## API 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.
```javascript
const fire = require("js-fire");const calculator = {
__description__: "I am a math machine",
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:
```bash
node calculator.js double --number=15 # 30
``````bash
node calculator.js misc hello hobochild # 'hello hobochild'
```Automactic `--help` command.
```bash
node calculator.js --helpUSAGE:
node calculator.jsDESCRIPTION:
I am a math machineCOMMANDS:
half --number=
double --number=
add --n1=3.141592653589793 --n2=misc
year
brand
hello --name=
```Automatic `--interactive` mode:
[![asciicast](https://asciinema.org/a/QdxxOZgsK4Wp0nxT7ZEn6mXIi.svg)](https://asciinema.org/a/QdxxOZgsK4Wp0nxT7ZEn6mXIi)
For additional examples, see [/examples](/examples).
## CLI Usage
js-fire exposes a CLI that takes modulePath and passes it to `js-fire`.
```bash
USAGE:
js-fire --modulePath=
```### Example
So you can js-fire on _most_ js modules.
```bash
js-fire fs -- writeFileSync --path=hello.txt --data="hiii"
```You can also use `interactive` and `help` mode to explore a modules api:
```bash
js-fire fs -- -hUSAGE:
js-fireCOMMANDS:
appendFile --path= --data= --options= --callback=
appendFileSync --path= --data= --options=
access --path= --mode= --callback=
accessSync --path= --mode=
chown --path= --uid= --gid= --callback=
chownSync --path= --uid= --gid=
chmod --path= --mode= --callback=
chmodSync --path= --mode=
close --fd= --callback=
closeSync --fd=
copyFile --src= --dest= --flags= --callback=
copyFileSync --src= --dest= --flags=
createReadStream --path= --options=
createWriteStream --path= --options=
exists --path= --callback=
existsSync --path=
...
```