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

Commit 49b77b4

Browse files
committed
early init cli work
1 parent da03761 commit 49b77b4

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed

src/cli/commands/init.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const Command = require('ronin').Command
2+
const IpfsRepo = require('ipfs-repo')
3+
const Ipfs = require('../../core')
24

35
module.exports = Command.extend({
4-
desc: 'Initialize ipfs local configuration',
6+
desc: 'Initialize a local IPFS local node',
57

68
options: {
79
bits: {
@@ -22,5 +24,37 @@ module.exports = Command.extend({
2224
}
2325
},
2426

25-
run: () => {}
27+
run: (bits, force, empty) => {
28+
// TODO: what blob store do I use for browser? indexdb, right?
29+
// well, this IS cli, and there's no browser cli :P
30+
var someBlobStore = require('fs-blob-store')
31+
32+
// TODO: --force + --empty-repo will keep your default assets, right?
33+
// TODO: where to init at? $IPFS_PATH var? homedir/.ipfs otherwise? sounds like a helper method job
34+
const repo = new IpfsRepo('/tmp/my-little-repo', {
35+
stores: {
36+
keys: someBlobStore,
37+
config: someBlobStore,
38+
datastore: someBlobStore,
39+
logs: someBlobStore,
40+
locks: someBlobStore,
41+
version: someBlobStore
42+
}
43+
})
44+
45+
var ipfs = new Ipfs(repo)
46+
ipfs.init({
47+
bits: bits,
48+
force: force,
49+
emptyRepo: empty
50+
}, function (err, res) {
51+
if (err) {
52+
console.error(err.toString())
53+
process.exit(1)
54+
}
55+
56+
// TODO: what console output is desirable? any? mimick go-ipfs?
57+
console.log('res', res)
58+
})
59+
}
2660
})

tests/test-cli/test-init.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* eslint-env mocha */
2+
3+
const expect = require('chai').expect
4+
const nexpect = require('nexpect')
5+
6+
describe('init', () => {
7+
it('basic', (done) => {
8+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'init'])
9+
.run((err, stdout, exitcode) => {
10+
expect(err).to.not.exist
11+
done()
12+
})
13+
})
14+
15+
it('bits', (done) => {
16+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'init', '--bits', '64'])
17+
.run((err, stdout, exitcode) => {
18+
expect(err).to.not.exist
19+
done()
20+
})
21+
})
22+
23+
it('empty', (done) => {
24+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'init', '--bits', '64', '--empty-repo', 'true'])
25+
.run((err, stdout, exitcode) => {
26+
expect(err).to.not.exist
27+
done()
28+
})
29+
})
30+
31+
it('force', (done) => {
32+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'init', '--bits', '64', '--force'])
33+
.run((err, stdout, exitcode) => {
34+
expect(err).to.not.exist
35+
expect(exitcode).to.equal(0)
36+
37+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'init', '--bits', '64'])
38+
.run((err, stdout, exitcode) => {
39+
expect(err).to.not.exist
40+
expect(exitcode).to.equal(1)
41+
42+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'init', '--bits', '64', '--force'])
43+
.run((err, stdout, exitcode) => {
44+
expect(err).to.not.exist
45+
expect(exitcode).to.equal(0)
46+
done()
47+
})
48+
})
49+
})
50+
})
51+
})
52+

0 commit comments

Comments
 (0)