Skip to content

Commit 11ab513

Browse files
authored
Merge pull request #1168 from gatos-jd/20190408/config-file-behavior
Changing startup behavior around config file
2 parents aa10ba3 + c8ca1b8 commit 11ab513

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

bin/lib/cli-utils.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const fs = require('fs-extra')
2-
const { cyan, bold } = require('colorette')
2+
const { red, cyan, bold } = require('colorette')
33
const { URL } = require('url')
44
const LDP = require('../../lib/ldp')
55
const AccountManager = require('../../lib/models/account-manager')
@@ -41,7 +41,22 @@ function loadConfig (program, options) {
4141
const config = JSON.parse(file)
4242
argv = { ...config, ...argv }
4343
} catch (err) {
44-
// No file exists, not a problem
44+
// If config file was specified, but it doesn't exist, stop with error message
45+
if (typeof argv['configFile'] !== 'undefined') {
46+
if (!fs.existsSync(configFile)) {
47+
console.log(red(bold('ERR')), 'Config file ' + configFile + ' doesn\'t exist.')
48+
process.exit(1)
49+
}
50+
}
51+
52+
// If the file exists, but parsing failed, stop with error message
53+
if (fs.existsSync(configFile)) {
54+
console.log(red(bold('ERR')), 'config file ' + configFile + ' couldn\'t be parsed: ' + err)
55+
process.exit(1)
56+
}
57+
58+
// Legacy behavior - if config file does not exist, start with default
59+
// values, but an info message to create a config file.
4560
console.log(cyan(bold('TIP')), 'create a config.json: `$ solid init`')
4661
}
4762

0 commit comments

Comments
 (0)