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

Commit

Permalink
Merge pull request #475 from ipfs/issue-286-init-output
Browse files Browse the repository at this point in the history
fix(cli): add output for cli init
  • Loading branch information
daviddias authored Sep 12, 2016
2 parents e0b69a8 + 29c9793 commit 37db11e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cli/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ module.exports = {
handler (argv) {
const path = utils.getRepoPath()

const log = utils.createLogger(true)
log(`initializing ipfs node at ${path}`)

const repo = new IpfsRepo(path, {
stores: Store
})
Expand All @@ -41,7 +44,8 @@ module.exports = {
ipfs.init({
bits: argv.bits,
force: argv.force,
emptyRepo: argv.emptyRepo
emptyRepo: argv.emptyRepo,
log
}, function (err) {
if (err) {
console.error(err.toString())
Expand Down
15 changes: 15 additions & 0 deletions src/cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,18 @@ exports.getIPFS = (callback) => {
exports.getRepoPath = () => {
return process.env.IPFS_PATH || os.homedir() + '/.ipfs'
}

exports.createLogger = (visible) => {
return (msg, newline) => {
if (newline === undefined) {
newline = true
}
if (visible) {
if (msg === undefined) {
msg = ''
}
msg = newline ? msg + '\n' : msg
process.stdout.write(msg)
}
}
}
14 changes: 14 additions & 0 deletions src/core/ipfs/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const fs = require('fs')
const importer = require('ipfs-unixfs-engine').importer
const pull = require('pull-stream')
const file = require('pull-file')
const mh = require('multihashes')

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

opts.emptyRepo = opts.emptyRepo || false
opts.bits = opts.bits || 2048
opts.log = opts.log || function () {}

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

// Generate peer identity keypair + transform to desired format + add to config.
function generateAndSetKeypair () {
opts.log(`generating ${opts.bits}-bit RSA keypair...`, false)
var keys = peerId.create({
bits: opts.bits
})
config.Identity = {
PeerID: keys.toB58String(),
PrivKey: keys.privKey.bytes.toString('base64')
}
opts.log('done')
opts.log('peer identity: ' + config.Identity.PeerID)

writeVersion()
}
Expand Down Expand Up @@ -108,6 +113,15 @@ module.exports = function init (self) {
}),
pull.filter(Boolean),
importer(dag),
pull.through((el) => {
if (el.path === 'files/init-docs/docs') {
const hash = mh.toB58String(el.multihash)
opts.log('to get started, enter:')
opts.log()
opts.log(`\t jsipfs files cat /ipfs/${hash}/readme`)
opts.log()
}
}),
pull.onEnd((err) => {
if (err) return callback(err)

Expand Down

0 comments on commit 37db11e

Please sign in to comment.