Skip to content

Commit

Permalink
Welcome back, good-looking usage information
Browse files Browse the repository at this point in the history
Now that we're caching the deps, we can use args again
  • Loading branch information
leo committed Feb 4, 2017
1 parent 75eaf94 commit daa6b65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
41 changes: 9 additions & 32 deletions bin/micro.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,20 @@
const {resolve} = require('path')

// Packages
const parse = require('minimist')
const args = require('args')
const asyncToGen = require('async-to-gen/register')
const updateNotifier = require('update-notifier')
const nodeVersion = require('node-version')

// Ours
const pkg = require('../package')

const args = parse(process.argv, {
alias: {
H: 'host',
h: 'help',
p: 'port'
},
boolean: ['h'],
default: {
H: '0.0.0.0',
p: 3000
}
})

let [,, file] = args._

const help = () => {
console.log(`Usage: micro [opts] <file>
-H, --host Host to listen on [0.0.0.0]
-p, --port Port to listen on [3000]
-h, --help Show this help message`)
}
args
.option('port', 'Port to listen on', 3000)
.option(['H', 'host'], 'Host to listen on', '0.0.0.0')

if (args.h) {
help()
process.exit(0)
}
const flags = args.parse(process.argv)
let file = args.sub[0]

// Throw an error if node version is too low
if (nodeVersion.major < 6) {
Expand All @@ -59,8 +39,7 @@ if (!file) {

if (!file) {
console.error('micro: Please supply a file.')
help()
process.exit(1)
args.showHelp()
}

if ('/' !== file[0]) {
Expand Down Expand Up @@ -103,13 +82,11 @@ if ('function' !== typeof mod) {
process.exit(1)
}

const {port, host} = args

serve(mod).listen(port, host, err => {
serve(mod).listen(flags.port, flags.host, err => {
if (err) {
console.error('micro:', err.stack)
process.exit(1)
}

console.log(`> Ready! Listening on http://${host}:${port}`)
console.log(`> Ready! Listening on http://${flags.host}:${flags.port}`)
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
"xo": "^0.17.0"
},
"dependencies": {
"args": "^2.2.4",
"async-to-gen": "1.3.1",
"isstream": "0.1.2",
"media-typer": "0.3.0",
"minimist": "1.2.0",
"node-version": "^1.0.0",
"raw-body": "2.2.0",
"update-notifier": "^1.0.3"
Expand Down

0 comments on commit daa6b65

Please sign in to comment.