Skip to content

Commit 9c17780

Browse files
committed
Merge pull request #14 from jarvys/master
add alias for port and add `-s` option
2 parents 085a6aa + 23a7cd1 commit 9c17780

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

bin/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ var cli = require('../src/cli')
66
var notifier = updateNotifier({packagePath: '../package'})
77
if (notifier.update) notifier.notify()
88

9-
var argv = minimist(process.argv.slice(2))
9+
var argv = minimist(process.argv.slice(2), {
10+
boolean: ["silent"],
11+
alias: {
12+
'p': 'port',
13+
's': 'silent'
14+
},
15+
default: {
16+
silent: false
17+
}
18+
})
1019

11-
cli.run(argv)
20+
cli.run(argv)

src/cli.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,31 @@ function help() {
1919
}
2020

2121
// Start server
22-
function start(port) {
22+
function start(port, silent) {
2323
for (var prop in low.db) {
2424
console.log('http://localhost:' + port + '/' + chalk.green(prop))
2525
}
2626

27-
console.log(
28-
'\nEnter ' + chalk.green('`s`') + ' at any time to create a snapshot of the db\n'
29-
)
30-
process.stdin.resume()
31-
process.stdin.setEncoding('utf8')
32-
process.stdin.on('data', function (chunk) {
33-
if (chunk.trim().toLowerCase() === 's') {
34-
var file = 'db-' + Date.now() + '.json'
35-
low.save(file)
36-
console.log('\nSaved snapshot to ' + chalk.green(file) + '\n')
37-
}
38-
})
27+
if(!silent) {
28+
console.log(
29+
'\nEnter ' + chalk.green('`s`') + ' at any time to create a snapshot of the db\n'
30+
)
31+
process.stdin.resume()
32+
process.stdin.setEncoding('utf8')
33+
process.stdin.on('data', function (chunk) {
34+
if (chunk.trim().toLowerCase() === 's') {
35+
var file = 'db-' + Date.now() + '.json'
36+
low.save(file)
37+
console.log('\nSaved snapshot to ' + chalk.green(file) + '\n')
38+
}
39+
})
40+
}
3941

4042
server.listen(port)
4143
}
4244

4345
// Load source
44-
function load(source, port) {
46+
function load(source, port, silent) {
4547
console.log(chalk.green('\n{^ ^} Heya!\n'))
4648

4749
console.log('Loading database from ' + source + '\n')
@@ -50,13 +52,13 @@ function load(source, port) {
5052
var path = process.cwd() + '/' + source
5153
low.path = path
5254
low.db = require(path);
53-
start(port)
55+
start(port, silent)
5456
}
5557

5658
if (/\.js$/.test(source)) {
5759
var path = process.cwd() + '/' + source
5860
low.db = require(path).run();
59-
start(port)
61+
start(port, silent)
6062
}
6163

6264
if (/^http/.test(source)) {
@@ -67,7 +69,7 @@ function load(source, port) {
6769
console.error(err)
6870
} else {
6971
low.db = JSON.parse(res.text)
70-
start(port)
72+
start(port, silent)
7173
}
7274
})
7375
}
@@ -77,9 +79,10 @@ function load(source, port) {
7779
function run(argv) {
7880
var source = argv._[0]
7981
var port = argv.port || 3000
82+
var silent = argv.silent
8083

8184
if (argv.version) return version()
82-
if (source) return load(source, port)
85+
if (source) return load(source, port, silent)
8386

8487
help()
8588
}

0 commit comments

Comments
 (0)