Skip to content

Commit

Permalink
try to create config dir (default: ~/.mediachain/aleph) if it doesn't…
Browse files Browse the repository at this point in the history
… exist
  • Loading branch information
yusefnapora committed Nov 18, 2016
1 parent 3dfad5f commit cd8df36
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"libp2p-websockets": "0.9.1",
"lodash": "^4.17.1",
"mafmt": "^2.1.2",
"mkdirp": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"multiaddr": "2.1.0",
"multihashes": "^0.2.2",
"multihashing": "^0.2.1",
Expand Down
21 changes: 18 additions & 3 deletions src/peer/repl/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
// @flow

const os = require('os')
const path = require('path')
const mkdirp = require('mkdirp')
// TODO: for bonus points, specify this as option, too
const home = os.homedir() + '/.mediachain/aleph/'
const home = path.join(os.homedir(), '.mediachain', 'aleph')

function ensureDirExists (filePath: string, fileDescription = 'file') {
const basedir = path.dirname(filePath)
try {
mkdirp.sync(basedir)
} catch (err) {
throw new Error(
`Unable to create parent directory for ${fileDescription} at ${filePath}: ${err.message}`)
}
return filePath
}

require('yargs')
.usage('Usage: $0 [options] <command> [command-options]')
Expand All @@ -15,16 +28,18 @@ require('yargs')
// this is the only way to get useful config in subcommands
'config': true,
'global': true,
'default': home + 'config.json'
'default': path.join(home, 'config.json')
},
'identityPath': {
'global': true,
'default': home + 'identity.node'
'default': path.join(home, 'identity.node')
},
'remotePeer': {
'global': true,
'type': 'string',
'describe': 'The remote peer to pair with (multiaddress)'
}
})
.coerce('config', filePath => ensureDirExists(filePath, 'config file'))
.coerce('identityPath', filePath => ensureDirExists(filePath, 'identity file'))
.argv

0 comments on commit cd8df36

Please sign in to comment.