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 #48 from ipfs/feat/config
Browse files Browse the repository at this point in the history
WIP feat/config
  • Loading branch information
daviddias committed Jan 14, 2016
2 parents 24f126a + 64154d6 commit de3aa7d
Show file tree
Hide file tree
Showing 28 changed files with 314 additions and 109 deletions.
3 changes: 2 additions & 1 deletion src/cli/commands/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const Command = require('ronin').Command
module.exports = Command.extend({
desc: '',

run: name => {}
run: name => {
}
})
4 changes: 3 additions & 1 deletion src/cli/commands/bootstrap/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ module.exports = Command.extend({
var node = new IPFS()
node.bootstrap.list((err, list) => {
if (err) { return log.error(err) }
list.forEach(node => { console.log(node) })
list.forEach(node => {
console.log(node)
})
})
}
})
3 changes: 2 additions & 1 deletion src/cli/commands/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const Command = require('ronin').Command
module.exports = Command.extend({
desc: '',

run: name => {}
run: name => {
}
})
36 changes: 36 additions & 0 deletions src/cli/commands/config/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict'

const Command = require('ronin').Command
const IPFS = require('../../../ipfs-core')
const debug = require('debug')
const log = debug('cli:version')
log.error = debug('cli:version:error')

module.exports = Command.extend({
desc: 'Shows IPFS version information',

options: {
number: {
alias: 'n',
type: 'boolean',
default: false
},
commit: {
type: 'boolean',
default: false
},
repo: {
type: 'boolean',
default: false
}
},

run: (name) => {
var node = new IPFS()
node.version((err, version) => {
if (err) { return log.error(err) }

console.log(version)
})
}
})
25 changes: 25 additions & 0 deletions src/cli/commands/config/replace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict'

const Command = require('ronin').Command
const IPFS = require('../../../ipfs-core')
const debug = require('debug')
const path = require('path')
const log = debug('cli:version')
log.error = debug('cli:version:error')

module.exports = Command.extend({
desc: 'Replaces the config with <file>',

options: {},

run: (configPath) => {
var node = new IPFS()
var config = require(path.resolve(process.cwd(), configPath))

node.config.replace(config, (err, version) => {
if (err) { return log.error(err) }

console.log(version)
})
}
})
22 changes: 22 additions & 0 deletions src/cli/commands/config/show.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

const Command = require('ronin').Command
const IPFS = require('../../../ipfs-core')
const debug = require('debug')
const log = debug('cli:version')
log.error = debug('cli:version:error')

module.exports = Command.extend({
desc: 'Outputs the content of the config file',

options: {},

run: () => {
var node = new IPFS()
node.config.show((err, config) => {
if (err) { return log.error(err) }

console.log(JSON.stringify(config, null, 4))
})
}
})
3 changes: 2 additions & 1 deletion src/cli/commands/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const Command = require('ronin').Command
module.exports = Command.extend({
desc: '',

run: name => {}
run: name => {
}
})
3 changes: 2 additions & 1 deletion src/cli/commands/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ const Command = require('ronin').Command
module.exports = Command.extend({
desc: '',

run: name => {}
run: name => {
}
})
5 changes: 3 additions & 2 deletions src/cli/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ module.exports = Command.extend({
'empty-repo': {
alias: 'e',
type: 'boolean',
desc: 'Don\'t add and pin help files to the local storage'
desc: "Don't add and pin help files to the local storage"
}
},

run: name => {}
run: name => {
}
})
3 changes: 2 additions & 1 deletion src/cli/commands/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const Command = require('ronin').Command
module.exports = Command.extend({
desc: '',

run: name => {}
run: name => {
}
})
3 changes: 2 additions & 1 deletion src/cli/commands/mount.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const Command = require('ronin').Command
module.exports = Command.extend({
desc: '',

run: name => {}
run: name => {
}
})
3 changes: 2 additions & 1 deletion src/cli/commands/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const Command = require('ronin').Command
module.exports = Command.extend({
desc: '',

run: name => {}
run: name => {
}
})
3 changes: 2 additions & 1 deletion src/cli/commands/refs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const Command = require('ronin').Command
module.exports = Command.extend({
desc: '',

run: name => {}
run: name => {
}
})
3 changes: 1 addition & 2 deletions src/cli/commands/repo/gc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ module.exports = Command.extend({
options: {
},

run: function (name) {
}
run: function (name) {}
})
3 changes: 1 addition & 2 deletions src/cli/commands/repo/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ module.exports = Command.extend({
options: {
},

run: function (name) {
}
run: function (name) {}
})
3 changes: 2 additions & 1 deletion src/cli/commands/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const Command = require('ronin').Command
module.exports = Command.extend({
desc: '',

run: name => {}
run: name => {
}
})
3 changes: 2 additions & 1 deletion src/cli/commands/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const Command = require('ronin').Command
module.exports = Command.extend({
desc: '',

run: name => {}
run: name => {
}
})
1 change: 0 additions & 1 deletion src/http-api/resources/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ exports.get = (request, reply) => {
return reply(id)
})
}

1 change: 0 additions & 1 deletion src/http-api/resources/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ exports.get = (request, reply) => {
return reply(version)
})
}

14 changes: 14 additions & 0 deletions src/ipfs-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,18 @@ function IPFS () {
})
}
}

this.config = {
// cli only feature built with show and replace
// edit: (callback) => {},
replace: (config, callback) => {
repo.config.set(config, callback)
},
show: callback => {
repo.config.get((err, config) => {
if (err) { return callback(err) }
callback(null, config)
})
}
}
}
7 changes: 3 additions & 4 deletions tests/test-api/test-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ describe('id', function () {
}, res => {
expect(res.result).to.deep.equal({ ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A',
PublicKey: '',
Addresses:
{ Swarm: [ '/ip4/0.0.0.0/tcp/4001', '/ip6/::/tcp/4001' ],
API: '/ip4/127.0.0.1/tcp/5001',
Gateway: '/ip4/127.0.0.1/tcp/8080' },
Addresses: { Swarm: [ '/ip4/0.0.0.0/tcp/4001', '/ip6/::/tcp/4001' ],
API: '/ip4/127.0.0.1/tcp/5001',
Gateway: '/ip4/127.0.0.1/tcp/8080' },
AgentVersion: 'js-ipfs',
ProtocolVersion: '9000'
})
Expand Down
56 changes: 28 additions & 28 deletions tests/test-cli-offline/test-bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,43 @@ describe('bootstrap', () => {

it('list the bootstrap nodes', done => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'list'])
.run((err, stdout, exitcode) => {
expect(stdout).to.deep.equal(defaultList)
expect(err).to.not.exist
expect(exitcode).to.equal(0)
done()
})
.run((err, stdout, exitcode) => {
expect(stdout).to.deep.equal(defaultList)
expect(err).to.not.exist
expect(exitcode).to.equal(0)
done()
})
})

it('add another bootstrap node', done => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'add', '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT'])
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)

nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'list'])
.run((err, stdout, exitcode) => {
expect(stdout).to.deep.equal(updatedList)
expect(err).to.not.exist
expect(exitcode).to.equal(0)
done()
})
})
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'list'])
.run((err, stdout, exitcode) => {
expect(stdout).to.deep.equal(updatedList)
expect(err).to.not.exist
expect(exitcode).to.equal(0)
done()
})
})
})

it('rm a bootstrap node', done => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'rm', '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT'])
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)

nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'list'])
.run((err, stdout, exitcode) => {
expect(stdout).to.deep.equal(defaultList)
expect(err).to.not.exist
expect(exitcode).to.equal(0)
done()
})
})
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'list'])
.run((err, stdout, exitcode) => {
expect(stdout).to.deep.equal(defaultList)
expect(err).to.not.exist
expect(exitcode).to.equal(0)
done()
})
})
})
})
42 changes: 21 additions & 21 deletions tests/test-cli-offline/test-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ const nexpect = require('nexpect')
describe('id', () => {
it('get the id', done => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'id'])
.run((err, stdout, exitcode) => {
var expected = [ '{ ID: \'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A\',',
' PublicKey: \'\',',
' Addresses: ',
' { Swarm: [ \'/ip4/0.0.0.0/tcp/4001\', \'/ip6/::/tcp/4001\' ],',
' API: \'/ip4/127.0.0.1/tcp/5001\',',
' Gateway: \'/ip4/127.0.0.1/tcp/8080\' },',
' AgentVersion: \'js-ipfs\',',
' ProtocolVersion: \'9000\' }' ]
.run((err, stdout, exitcode) => {
var expected = [ "{ ID: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A',",
" PublicKey: '',",
' Addresses: ',
" { Swarm: [ '/ip4/0.0.0.0/tcp/4001', '/ip6/::/tcp/4001' ],",
" API: '/ip4/127.0.0.1/tcp/5001',",
" Gateway: '/ip4/127.0.0.1/tcp/8080' },",
" AgentVersion: 'js-ipfs',",
" ProtocolVersion: '9000' }" ]

expect(stdout[0]).to.equal(expected[0])
expect(stdout[1]).to.equal(expected[1])
expect(stdout[2]).to.equal(expected[2])
expect(stdout[3]).to.equal(expected[3])
expect(stdout[4]).to.equal(expected[4])
expect(stdout[5]).to.equal(expected[5])
expect(stdout[6]).to.equal(expected[6])
expect(stdout[7]).to.equal(expected[7])
expect(err).to.not.exist
expect(exitcode).to.equal(0)
done()
})
expect(stdout[0]).to.equal(expected[0])
expect(stdout[1]).to.equal(expected[1])
expect(stdout[2]).to.equal(expected[2])
expect(stdout[3]).to.equal(expected[3])
expect(stdout[4]).to.equal(expected[4])
expect(stdout[5]).to.equal(expected[5])
expect(stdout[6]).to.equal(expected[6])
expect(stdout[7]).to.equal(expected[7])
expect(err).to.not.exist
expect(exitcode).to.equal(0)
done()
})
})
})
12 changes: 6 additions & 6 deletions tests/test-cli-offline/test-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const nexpect = require('nexpect')
describe('version', () => {
it('get the version', done => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'version'])
.expect('0.4.0-dev')
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)
done()
})
.expect('0.4.0-dev')
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)
done()
})
})
})
Loading

0 comments on commit de3aa7d

Please sign in to comment.