Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit dd264a6

Browse files
committed
fix(cli): add output for cli init
Shows exactly same information as go-ipfs except for change of the cmd + cat so `ipfs cat` turns into `jsipfs files cat` instead. Ref: issue #286
1 parent 636307f commit dd264a6

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/cli/commands/init.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ module.exports = {
3232
handler (argv) {
3333
const path = utils.getRepoPath()
3434

35+
const log = utils.createLogger(true)
36+
log(`initializing ipfs node at ${path}`)
37+
3538
const repo = new IpfsRepo(path, {
3639
stores: Store
3740
})
@@ -41,7 +44,8 @@ module.exports = {
4144
ipfs.init({
4245
bits: argv.bits,
4346
force: argv.force,
44-
emptyRepo: argv.emptyRepo
47+
emptyRepo: argv.emptyRepo,
48+
log
4549
}, function (err) {
4650
if (err) {
4751
console.error(err.toString())

src/cli/utils.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,15 @@ exports.getIPFS = (callback) => {
4949
exports.getRepoPath = () => {
5050
return process.env.IPFS_PATH || os.homedir() + '/.ipfs'
5151
}
52+
53+
exports.createLogger = (visible) => {
54+
return (msg, newline = true) => {
55+
if (visible) {
56+
if (msg === undefined) {
57+
msg = ''
58+
}
59+
msg = newline ? msg + '\n' : msg
60+
process.stdout.write(msg)
61+
}
62+
}
63+
}

src/core/ipfs/init.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const fs = require('fs')
99
const importer = require('ipfs-unixfs-engine').importer
1010
const pull = require('pull-stream')
1111
const file = require('pull-file')
12+
const mh = require('multihashes')
1213

1314
module.exports = function init (self) {
1415
return (opts, callback) => {
@@ -19,6 +20,7 @@ module.exports = function init (self) {
1920

2021
opts.emptyRepo = opts.emptyRepo || false
2122
opts.bits = opts.bits || 2048
23+
opts.log = opts.log || function () {}
2224

2325
let config
2426
// Pre-set config values.
@@ -47,13 +49,16 @@ module.exports = function init (self) {
4749

4850
// Generate peer identity keypair + transform to desired format + add to config.
4951
function generateAndSetKeypair () {
52+
opts.log(`generating ${opts.bits}-bit RSA keypair...`, false)
5053
var keys = peerId.create({
5154
bits: opts.bits
5255
})
5356
config.Identity = {
5457
PeerID: keys.toB58String(),
5558
PrivKey: keys.privKey.bytes.toString('base64')
5659
}
60+
opts.log('done')
61+
opts.log('peer identity: ' + config.Identity.PeerID)
5762

5863
writeVersion()
5964
}
@@ -108,6 +113,16 @@ module.exports = function init (self) {
108113
}),
109114
pull.filter(Boolean),
110115
importer(dag),
116+
pull.map((el) => {
117+
if (el.path === 'files/init-docs/docs') {
118+
const hash = mh.toB58String(el.multihash)
119+
opts.log('to get started, enter:')
120+
opts.log()
121+
opts.log(`\t jsipfs files cat /ipfs/${hash}/readme`)
122+
opts.log()
123+
}
124+
return el
125+
}),
111126
pull.onEnd((err) => {
112127
if (err) return callback(err)
113128

0 commit comments

Comments
 (0)