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

Commit

Permalink
feat: ipfs version flags + ipfs repo version (#1181)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonKrone committed Feb 16, 2018
1 parent 58ef77b commit fe602f0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/cli/commands/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function version (self) {

self.repo.version((err, repoVersion) => {
if (err) {
callback(err)
return callback(err)
}

callback(null, {
Expand Down
2 changes: 2 additions & 0 deletions src/http/api/resources/repo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const boom = require('boom')

exports = module.exports

exports.version = (request, reply) => {
Expand Down
37 changes: 33 additions & 4 deletions test/cli/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () =>
Expand Down Expand Up @@ -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`)
})
})
}))

0 comments on commit fe602f0

Please sign in to comment.