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

feat: add slient option #1712

Merged
merged 9 commits into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ Instead of a boolean, you may provide an object with custom initialization optio

A passphrase to encrypt/decrypt your keys.

##### `options.silent`

| Type | Default |
|------|---------|
| Boolean | `false` |

Prevents all logging output from the IPFS node.

##### `options.relay`

| Type | Default |
Expand Down
7 changes: 6 additions & 1 deletion src/cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ const cli = yargs
desc: 'Write no output',
type: 'boolean',
default: false,
coerce: ('silent', silent => silent ? utils.disablePrinting() : silent)
coerce: ('silent', silent => {
if (silent) {
utils.disablePrinting()
}
return silent
})
})
.option('pass', {
desc: 'Pass phrase for the keys',
Expand Down
1 change: 1 addition & 0 deletions src/cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ exports.getIPFS = (argv, callback) => {
// Required inline to reduce startup time
const IPFS = require('../core')
const node = new IPFS({
silent: argv.silent,
repo: exports.getRepoPath(),
init: false,
start: false,
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module.exports = function libp2p (self) {
if (err) { return callback(err) }

self._libp2pNode.peerInfo.multiaddrs.forEach((ma) => {
console.log('Swarm listening on', ma.toString())
self._print('Swarm listening on', ma.toString())
})

callback()
Expand Down
1 change: 1 addition & 0 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class IPFS extends EventEmitter {
this._preload = preload(this)
this._mfsPreload = mfsPreload(this)
this._ipns = undefined
this._print = this._options.silent ? this.log : console.log

// IPFS Core exposed components
// - for booting up a node
Expand Down
7 changes: 4 additions & 3 deletions src/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function HttpApi (repo, config, cliArgs) {
try {
// start the daemon
this.node = new IPFS({
silent: cliArgs.silent,
repo: repo,
init: init,
start: true,
Expand Down Expand Up @@ -157,9 +158,9 @@ function HttpApi (repo, config, cliArgs) {
api.info.ma = uriToMultiaddr(api.info.uri)
gateway.info.ma = uriToMultiaddr(gateway.info.uri)

console.log('API listening on %s', api.info.ma)
console.log('Gateway (read only) listening on %s', gateway.info.ma)
console.log('Web UI available at %s', api.info.uri + '/webui')
this.node._print('API listening on %s', api.info.ma)
this.node._print('Gateway (read only) listening on %s', gateway.info.ma)
this.node._print('Web UI available at %s', api.info.uri + '/webui')

// for the CLI to know the where abouts of the API
this.node._repo.apiAddr.set(api.info.ma, cb)
Expand Down
15 changes: 15 additions & 0 deletions test/cli/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ describe('daemon', () => {
})
})

it('should be silent', function (done) {
this.timeout(10 * 1000)
const res = ipfs('daemon --silent')
res.catch(function () {}) // Handles the unhandled promise rejection
let output = ''
const onData = (d) => { output += d }
res.stdout.on('data', onData)
res.stderr.on('data', onData)
setTimeout(function () {
res.kill()
expect(output).to.be.empty()
done()
}, 5 * 1000)
})

it('should present ipfs path help when option help is received', function (done) {
this.timeout(100 * 1000)

Expand Down
16 changes: 16 additions & 0 deletions test/core/create-node.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const series = require('async/series')
const sinon = require('sinon')
const waterfall = require('async/waterfall')
const parallel = require('async/parallel')
const os = require('os')
Expand Down Expand Up @@ -131,6 +132,21 @@ describe('create node', function () {
})
})

it('should be silent', (done) => {
sinon.spy(console, 'log')

const ipfs = new IPFS({
silent: true,
repo: tempRepo
})

ipfs.on('ready', () => {
expect(console.log.called).to.be.false()
console.log.restore()
done()
})
})

it('init: false errors (start default: true) and errors only once', function (done) {
this.timeout(80 * 1000)

Expand Down
3 changes: 3 additions & 0 deletions test/core/libp2p.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('libp2p customization', function () {
},
_peerInfo: peerInfo,
_peerBook: peerBook,
_print: console.log,
config: mockConfig,
_options: {
libp2p: (opts) => {
Expand Down Expand Up @@ -122,6 +123,7 @@ describe('libp2p customization', function () {
},
_peerInfo: peerInfo,
_peerBook: peerBook,
_print: console.log,
config: mockConfig
}

Expand Down Expand Up @@ -164,6 +166,7 @@ describe('libp2p customization', function () {
},
_peerInfo: peerInfo,
_peerBook: peerBook,
_print: console.log,
config: mockConfig,
_options: {
config: {
Expand Down