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 and ipfs repo version (#1199)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonKrone authored and daviddias committed Feb 1, 2018
1 parent 54d47e1 commit 62fd639
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"ipfs-block": "~0.6.1",
"ipfs-block-service": "~0.13.0",
"ipfs-multipart": "~0.1.0",
"ipfs-repo": "~0.18.5",
"ipfs-repo": "^0.18.6",
"ipfs-unixfs": "~0.1.14",
"ipfs-unixfs-engine": "~0.24.2",
"ipld-resolver": "~0.14.1",
Expand Down
11 changes: 7 additions & 4 deletions src/cli/commands/version.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const os = require('os')
const print = require('../utils').print

module.exports = {
Expand Down Expand Up @@ -32,22 +33,24 @@ module.exports = {
},

handler (argv) {
argv.ipfs.version((err, ipfs) => {
argv.ipfs.version((err, data) => {
if (err) {
throw err
}

const withCommit = argv.all || argv.commit
const parsedVersion = `${ipfs.version}${withCommit ? `-${ipfs.commit}` : ''}`
const parsedVersion = `${data.version}${withCommit ? `-${data.commit}` : ''}`

if (argv.repo) {
// go-ipfs prints only the number, even without the --number flag.
print(ipfs.repo)
print(data.repo)
} else if (argv.number) {
print(parsedVersion)
} else if (argv.all) {
print(`js-ipfs version: ${parsedVersion}`)
print(`Repo version: ${ipfs.repo}`)
print(`Repo version: ${data.repo}`)
print(`System version: ${os.arch()}/${os.platform()}`)
print(`Node.js version: ${process.version}`)
} else {
print(`js-ipfs version: ${parsedVersion}`)
}
Expand Down
21 changes: 20 additions & 1 deletion src/core/components/repo.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
'use strict'

const repoVersion = require('ipfs-repo').repoVersion

module.exports = function repo (self) {
return {
init: (bits, empty, callback) => {
// 1. check if repo already exists
},

/**
* If the repo has been initialized, report the current version.
* Otherwise report the version that would be initialized.
*
* @param {function(Error, Number)} [callback]
* @returns {undefined}
*/
version: (callback) => {
self._repo.version.get(callback)
self._repo._isInitialized(err => {
if (err) {
if (/ENOENT|not yet initialized/.test(err.message)) {
// this repo has not been initialized
return callback(null, repoVersion)
}
return callback(err)
}

self._repo.version.get(callback)
})
},

gc: function () {},
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) {
throw err
callback(err)
}

callback(null, {
Expand Down
2 changes: 1 addition & 1 deletion test/cli/files.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-env mocha */
'use strict'

const expect = require('chai').expect
const fs = require('fs')
const expect = require('chai').expect
const path = require('path')
const compareDir = require('dir-compare').compareSync
const rimraf = require('rimraf').sync
Expand Down
11 changes: 2 additions & 9 deletions test/cli/repo.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
/* eslint-env mocha */
'use strict'

const fs = require('fs')
const path = require('path')
const expect = require('chai').expect
const runOnAndOff = require('../utils/on-and-off')
const repoVersion = require('ipfs-repo').repoVersion

function getRepoVersion (repoPath) {
const versionPath = path.join(repoPath, 'version')
return String(fs.readFileSync(versionPath))
}
const runOnAndOff = require('../utils/on-and-off')

describe('repo', () => runOnAndOff((thing) => {
let ipfs
let repoVersion

before(() => {
ipfs = thing.ipfs
repoVersion = getRepoVersion(ipfs.repoPath)
})

it('get the repo version', () => {
Expand Down
70 changes: 40 additions & 30 deletions test/cli/version.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,69 @@
/* eslint max-nested-callbacks: ["error", 5] */
/* eslint-env mocha */
'use strict'

const fs = require('fs')
const path = require('path')
const os = require('os')
const expect = require('chai').expect
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', () => {
return ipfs('version').then((out) => {
it('get the version', () =>
ipfs('version').then(out =>
expect(out).to.eql(
`js-ipfs version: ${pkgversion}\n`
)
})
})
)
)

it('handles --number', () => {
return ipfs('version --number').then(out =>
it('handles --number', () =>
ipfs('version --number').then(out =>
expect(out).to.eql(`${pkgversion}\n`)
)
})
)

it('handles --commit', () => {
return ipfs('version --commit').then(out =>
it('handles --commit', () =>
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}
`
)
describe('handles --all', function () {
it('prints js-ipfs version', () =>
ipfs('version --all').then(out => {
expect(out).to.include(`js-ipfs version: ${pkgversion}`)
})
)

it('prints repo version', () =>
ipfs('version --all').then(out => {
expect(out).to.include(`Repo version: ${repoVersion}`)
})
)

it('prints arch/platform', () =>
ipfs('version --all').then(out => {
expect(out).to.include(`System version: ${os.arch()}/${os.platform()}`)
})
)

it('prints Node.js version', () =>
ipfs('version --all').then(out => {
expect(out).to.include(`Node.js version: ${process.version}`)
})
)
})

it('handles --repo', () => {
return ipfs('version --repo').then(out => {
it('handles --repo', () =>
ipfs('version --repo').then(out =>
expect(out).to.eql(`${repoVersion}\n`)
})
})
)
)
}))
5 changes: 4 additions & 1 deletion test/sharness/t0010-basic-commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ test_expect_success "ipfs version output looks good" '

test_expect_success "ipfs version --all has all required fields" '
ipfs version --all > version_all.txt &&
grep "js-ipfs version" version_all.txt
grep "js-ipfs version" version_all.txt &&
grep "Repo version" version_all.txt &&
grep "System version" version_all.txt &&
grep "Node.js version" version_all.txt
'

test_expect_success "ipfs help succeeds" '
Expand Down

0 comments on commit 62fd639

Please sign in to comment.