Skip to content

Instantly share code, notes, and snippets.

@yoshuawuyts
Last active August 29, 2015 14:26
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoshuawuyts/ba12001596cc001de52e to your computer and use it in GitHub Desktop.
Save yoshuawuyts/ba12001596cc001de52e to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const cliclopts = require('cliclopts')
const minimist = require('minimist')
const fs = require('fs')
const quickStub = require('./')
const opts = cliclopts([
{
name: 'help',
abbr: 'h',
boolean: true
},
{
name: 'verbose',
abbr: 'v',
boolean: true
}
])
const argv = minimist(process.argv.slice(2), opts.options())
// help
if (argv.help) usage(0)
if (process.argv.length <= 2 && process.stdin.isTTY) usage(1)
// version
if (argv.v || argv.version) {
process.stdout.write(require('../package.json').version)
process.exit(0)
}
// run commands
quickStub(argv)
// print usage
// num? -> null
function usage (exitCode) {
exitCode = exitCode || 0
fs.createReadStream(__dirname + '/usage.txt')
.pipe(process.stdout)
.on('close', process.exit.bind(null, exitCode))
}
quick-base - generate a fresh module
Usage: quick-base <name>
Options:
-h, --help Output usage information
-v, --version Output version number
Examples:
$ quick-base hello-world # generate 'hello-world' module
Docs: https://github.com/yoshuawuyts/quick-stub
Bugs: https://github.com/yoshuawuyts/quick-stub/issues
@yoshuawuyts
Copy link
Author

newer version, removed race conditions

#!/usr/bin/env node
const cliclopts = require('cliclopts')
const minimist = require('minimist')
const fs = require('fs')

const createPkg = require('../')

const opts = cliclopts([
  {
    name: 'help',
    abbr: 'h',
    boolean: true
  },
  {
    name: 'version',
    abbr: 'v',
    boolean: true
  },
  {
    name: 'directory',
    abbr: 'd',
    string: true,
    default: './'
  }
])

const argv = minimist(process.argv.slice(2), opts.options())

// parse options
if (argv.version) {
  const version = require('../package.json').version
  process.stdout.write('v' + version)
  process.exit(0)
}
else if (argv.help) usage(0)
else if (!argv._.length && process.stdin.isTTY) usage(1)
else createPkg(argv)

// print usage & exit
// num? -> null
function usage (exitCode) {
  fs.createReadStream(__dirname + '/usage.txt')
    .pipe(process.stdout)
    .on('close', process.exit.bind(null, exitCode))
}

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