Skip to content

Instantly share code, notes, and snippets.

@gubi
Last active February 9, 2017 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gubi/7ce02b0a3470a7abb5d4c6f0e4193892 to your computer and use it in GitHub Desktop.
Save gubi/7ce02b0a3470a7abb5d4c6f0e4193892 to your computer and use it in GitHub Desktop.
[
{
"name": "command",
"short": "c",
"type": "boolean",
"description": "Show this help",
"example": "'myapp --command=true|false' or 'myapp -c true|false'"
},
...
]

1. Execute the script without ./ prefix

from http://unix.stackexchange.com/questions/162134/how-to-execute-a-bash-script-without-typing

You need add directory with your script to the PATH variable:

export PATH=$PATH:/path/to/dir

or you can even add current directory to the PATH:

export PATH=$PATH:.

The later has some security drawback though.

2. Rename the file without ".js" extension

3. Add properly header

If you want that the file will be parsed as well you need to place this header in the first line:

#!/usr/bin/env node

4. Manage ARGV and colours

Include the argv module and the colors module:

var ARGV        = require("argv"),
    colors      = require("colors");

then you can configure args in an external json file:

**
 * Parse args in command line
 */
ARGS = ARGV.option(JSON.parse(
    FS.readFileSync(C_.adjustPath("argv.json"), "utf8")
)).version("v1.0").run();

5. Fantastic app

Consider also the readline module to build a quiz for variables if not provided

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment