diff --git a/src/cli/commands/version.js b/src/cli/commands/version.js index 6bb8447a2f..e578c899d6 100644 --- a/src/cli/commands/version.js +++ b/src/cli/commands/version.js @@ -33,22 +33,22 @@ module.exports = { }, handler (argv) { - argv.ipfs.version((err, data) => { + argv.ipfs.version((err, versions) => { if (err) { throw err } const withCommit = argv.all || argv.commit - const parsedVersion = `${data.version}${withCommit ? `-${data.commit}` : ''}` + const parsedVersion = `${versions.version}${withCommit ? `-${versions.commit}` : ''}` if (argv.repo) { // go-ipfs prints only the number, even without the --number flag. - print(data.repo) + print(versions.repo) } else if (argv.number) { print(parsedVersion) } else if (argv.all) { print(`js-ipfs version: ${parsedVersion}`) - print(`Repo version: ${data.repo}`) + print(`Repo version: ${versions.repo}`) print(`System version: ${os.arch()}/${os.platform()}`) print(`Node.js version: ${process.version}`) } else { diff --git a/src/core/components/version.js b/src/core/components/version.js index 1afbc7a7fb..c9b663dd6d 100644 --- a/src/core/components/version.js +++ b/src/core/components/version.js @@ -13,7 +13,7 @@ module.exports = function version (self) { self.repo.version((err, repoVersion) => { if (err) { - callback(err) + return callback(err) } callback(null, { diff --git a/src/http/api/resources/repo.js b/src/http/api/resources/repo.js index 394fda548e..b6d0a32190 100644 --- a/src/http/api/resources/repo.js +++ b/src/http/api/resources/repo.js @@ -1,5 +1,7 @@ 'use strict' +const boom = require('boom') + exports = module.exports exports.version = (request, reply) => { diff --git a/test/cli/version.js b/test/cli/version.js index 5bf740eb15..24b602acd2 100644 --- a/test/cli/version.js +++ b/test/cli/version.js @@ -8,11 +8,18 @@ const repoVersion = require('ipfs-repo').repoVersion const pkgversion = require('../../package.json').version const runOnAndOff = require('../utils/on-and-off') +function getRepoVersion (repoPath) { + const versionPath = path.join(repoPath, 'version') + return String(fs.readFileSync(versionPath)) +} + describe('version', () => runOnAndOff((thing) => { let ipfs + let repoVersion before(() => { ipfs = thing.ipfs + repoVersion = getRepoVersion(ipfs.repoPath) }) it('get the version', () => @@ -61,9 +68,31 @@ describe('version', () => runOnAndOff((thing) => { ) }) - it('handles --repo', () => - ipfs('version --repo').then(out => - expect(out).to.eql(`${repoVersion}\n`) + it('handles --number', () => { + return ipfs('version --number').then(out => + expect(out).to.eql(`${pkgversion}\n`) ) - ) + }) + + it('handles --commit', () => { + return ipfs('version --commit').then(out => + expect(out).to.eql(`js-ipfs version: ${pkgversion}-\n`) + ) + }) + + it('handles --all', () => { + return ipfs('version --all').then(out => + expect(out).to.include( + `js-ipfs version: ${pkgversion}- +Repo version: ${repoVersion} +` + ) + ) + }) + + it('handles --repo', () => { + return ipfs('version --repo').then(out => { + expect(out).to.eql(`${repoVersion}\n`) + }) + }) }))