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

Commit fe602f0

Browse files
committed
feat: ipfs version flags + ipfs repo version (#1181)
1 parent 58ef77b commit fe602f0

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

src/cli/commands/version.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ module.exports = {
3333
},
3434

3535
handler (argv) {
36-
argv.ipfs.version((err, data) => {
36+
argv.ipfs.version((err, versions) => {
3737
if (err) {
3838
throw err
3939
}
4040

4141
const withCommit = argv.all || argv.commit
42-
const parsedVersion = `${data.version}${withCommit ? `-${data.commit}` : ''}`
42+
const parsedVersion = `${versions.version}${withCommit ? `-${versions.commit}` : ''}`
4343

4444
if (argv.repo) {
4545
// go-ipfs prints only the number, even without the --number flag.
46-
print(data.repo)
46+
print(versions.repo)
4747
} else if (argv.number) {
4848
print(parsedVersion)
4949
} else if (argv.all) {
5050
print(`js-ipfs version: ${parsedVersion}`)
51-
print(`Repo version: ${data.repo}`)
51+
print(`Repo version: ${versions.repo}`)
5252
print(`System version: ${os.arch()}/${os.platform()}`)
5353
print(`Node.js version: ${process.version}`)
5454
} else {

src/core/components/version.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = function version (self) {
1313

1414
self.repo.version((err, repoVersion) => {
1515
if (err) {
16-
callback(err)
16+
return callback(err)
1717
}
1818

1919
callback(null, {

src/http/api/resources/repo.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict'
22

3+
const boom = require('boom')
4+
35
exports = module.exports
46

57
exports.version = (request, reply) => {

test/cli/version.js

+33-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@ const repoVersion = require('ipfs-repo').repoVersion
88
const pkgversion = require('../../package.json').version
99
const runOnAndOff = require('../utils/on-and-off')
1010

11+
function getRepoVersion (repoPath) {
12+
const versionPath = path.join(repoPath, 'version')
13+
return String(fs.readFileSync(versionPath))
14+
}
15+
1116
describe('version', () => runOnAndOff((thing) => {
1217
let ipfs
18+
let repoVersion
1319

1420
before(() => {
1521
ipfs = thing.ipfs
22+
repoVersion = getRepoVersion(ipfs.repoPath)
1623
})
1724

1825
it('get the version', () =>
@@ -61,9 +68,31 @@ describe('version', () => runOnAndOff((thing) => {
6168
)
6269
})
6370

64-
it('handles --repo', () =>
65-
ipfs('version --repo').then(out =>
66-
expect(out).to.eql(`${repoVersion}\n`)
71+
it('handles --number', () => {
72+
return ipfs('version --number').then(out =>
73+
expect(out).to.eql(`${pkgversion}\n`)
6774
)
68-
)
75+
})
76+
77+
it('handles --commit', () => {
78+
return ipfs('version --commit').then(out =>
79+
expect(out).to.eql(`js-ipfs version: ${pkgversion}-\n`)
80+
)
81+
})
82+
83+
it('handles --all', () => {
84+
return ipfs('version --all').then(out =>
85+
expect(out).to.include(
86+
`js-ipfs version: ${pkgversion}-
87+
Repo version: ${repoVersion}
88+
`
89+
)
90+
)
91+
})
92+
93+
it('handles --repo', () => {
94+
return ipfs('version --repo').then(out => {
95+
expect(out).to.eql(`${repoVersion}\n`)
96+
})
97+
})
6998
}))

0 commit comments

Comments
 (0)