@@ -19,29 +19,31 @@ function help() {
19
19
}
20
20
21
21
// Start server
22
- function start ( port ) {
22
+ function start ( port , silent ) {
23
23
for ( var prop in low . db ) {
24
24
console . log ( 'http://localhost:' + port + '/' + chalk . green ( prop ) )
25
25
}
26
26
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
+ }
39
41
40
42
server . listen ( port )
41
43
}
42
44
43
45
// Load source
44
- function load ( source , port ) {
46
+ function load ( source , port , silent ) {
45
47
console . log ( chalk . green ( '\n{^ ^} Heya!\n' ) )
46
48
47
49
console . log ( 'Loading database from ' + source + '\n' )
@@ -50,13 +52,13 @@ function load(source, port) {
50
52
var path = process . cwd ( ) + '/' + source
51
53
low . path = path
52
54
low . db = require ( path ) ;
53
- start ( port )
55
+ start ( port , silent )
54
56
}
55
57
56
58
if ( / \. j s $ / . test ( source ) ) {
57
59
var path = process . cwd ( ) + '/' + source
58
60
low . db = require ( path ) . run ( ) ;
59
- start ( port )
61
+ start ( port , silent )
60
62
}
61
63
62
64
if ( / ^ h t t p / . test ( source ) ) {
@@ -67,7 +69,7 @@ function load(source, port) {
67
69
console . error ( err )
68
70
} else {
69
71
low . db = JSON . parse ( res . text )
70
- start ( port )
72
+ start ( port , silent )
71
73
}
72
74
} )
73
75
}
@@ -77,9 +79,10 @@ function load(source, port) {
77
79
function run ( argv ) {
78
80
var source = argv . _ [ 0 ]
79
81
var port = argv . port || 3000
82
+ var silent = argv . silent
80
83
81
84
if ( argv . version ) return version ( )
82
- if ( source ) return load ( source , port )
85
+ if ( source ) return load ( source , port , silent )
83
86
84
87
help ( )
85
88
}
0 commit comments