mirror of
https://github.com/typicode/json-server.git
synced 2025-07-28 12:43:18 +08:00
Refactor CLI and add tests
This commit is contained in:
48
src/cli/index.js
Normal file
48
src/cli/index.js
Normal file
@ -0,0 +1,48 @@
|
||||
var updateNotifier = require('update-notifier')
|
||||
var yargs = require('yargs')
|
||||
var run = require('./run')
|
||||
var pkg = require('../../package.json')
|
||||
|
||||
module.exports = function () {
|
||||
|
||||
updateNotifier({ pkg: pkg }).notify()
|
||||
|
||||
var argv = yargs
|
||||
.usage('$0 [options] <source>')
|
||||
.options({
|
||||
port: {
|
||||
alias: 'p',
|
||||
description: 'Set port',
|
||||
default: 3000
|
||||
},
|
||||
host: {
|
||||
alias: 'H',
|
||||
description: 'Set host',
|
||||
default: '0.0.0.0'
|
||||
},
|
||||
watch: {
|
||||
alias: 'w',
|
||||
description: 'Watch file(s)'
|
||||
},
|
||||
routes: {
|
||||
alias: 'r',
|
||||
description: 'Load routes file'
|
||||
},
|
||||
id: {
|
||||
description: 'Set database id property (e.g. _id)',
|
||||
default: 'id'
|
||||
}
|
||||
})
|
||||
.boolean('watch')
|
||||
.help('help').alias('help', 'h')
|
||||
.version(pkg.version).alias('version', 'v')
|
||||
.example('$0 db.json', '')
|
||||
.example('$0 file.js', '')
|
||||
.example('$0 http://example.com/db.json', '')
|
||||
.epilog('https://github.com/typicode/json-server')
|
||||
.require(1, 'Missing <source> argument')
|
||||
.argv
|
||||
|
||||
run(argv)
|
||||
|
||||
}
|
Reference in New Issue
Block a user