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

Commit

Permalink
chore: rebase, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias committed Jul 22, 2019
1 parent 56843ba commit b9836a2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 48 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"async-iterator-to-stream": "^1.1.0",
"base32.js": "~0.1.0",
"bignumber.js": "^9.0.0",
"async-exit-hook": "^2.0.1",
"binary-querystring": "~0.1.2",
"bl": "^3.0.0",
"bs58": "^4.0.1",
Expand Down Expand Up @@ -169,7 +168,6 @@
"readable-stream": "^3.4.0",
"receptacle": "^1.3.2",
"semver": "^6.2.0",
"signal-exit": "^3.0.2",
"stream-to-pull-stream": "^1.7.3",
"superstruct": "~0.6.0",
"tar-stream": "^2.0.0",
Expand Down
78 changes: 34 additions & 44 deletions src/cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,34 @@
/* eslint-disable no-console */
'use strict'

process.on('uncaughtException', (err) => {
console.info(err)
const semver = require('semver')
const YargsPromise = require('yargs-promise')
const updateNotifier = require('update-notifier')
const debug = require('debug')('ipfs:cli')
const parser = require('./parser')
const commandAlias = require('./command-alias')
const { print } = require('./utils')
const pkg = require('../../package.json')

throw err
// Handle any uncaught error
process.once('uncaughtException', (err, origin) => {
if (origin === 'uncaughtException') {
print(err.message)
debug(err)
}
})

process.on('unhandledRejection', (err) => {
console.info(err)

throw err
process.once('unhandledRejection', (err) => {
print(err.message)
debug(err)
})

const semver = require('semver')
const pkg = require('../../package.json')

// Check for node version
if (!semver.satisfies(process.versions.node, pkg.engines.node)) {
console.error(`Please update your Node.js version to ${pkg.engines.node}`)
process.exit(1)
}

const YargsPromise = require('yargs-promise')
const updateNotifier = require('update-notifier')
const onExit = require('async-exit-hook')
const utils = require('./utils')
const print = utils.print
const debug = require('debug')('ipfs:cli')
const parser = require('./parser')
const commandAlias = require('./command-alias')

// Check if an update is available and notify
const oneWeek = 1000 * 60 * 60 * 24 * 7
updateNotifier({ pkg, updateCheckInterval: oneWeek }).notify()

Expand All @@ -50,30 +49,21 @@ cli
}
})
.catch(({ error, argv }) => {
console.log('TCL: error', error)

getIpfs = argv.getIpfs
if (error) {
throw error
if (error.message) {
print(error.message)
debug(error)
} else {
print('Unknown error, please re-run the command with DEBUG=ipfs:cli to see debug output')
debug(error)
}
process.exit(1)
})
.finally(() => {
if (getIpfs && getIpfs.instance) {
const cleanup = getIpfs.rest[0]
return cleanup()
}
throw new Error('Unknown error, please re-run the command with DEBUG=ipfs:cli to see debug output')
})

onExit(cb => {
// If an IPFS instance was used in the handler then clean it up here
if (getIpfs && getIpfs.instance) {
const cleanup = getIpfs.rest[0]

return cleanup()
.then(() => cb())
.catch(err => {
print(err.message)
debug(err)
cb()
})
}
cb()
})

onExit.unhandledRejectionHandler(err => {
print(err.message)
debug(err)
})
3 changes: 2 additions & 1 deletion src/cli/commands/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = {
argv.resolve((async () => {
const ipfs = await argv.getIpfs()
const id = await ipfs.id()
argv.print(JSON.stringify(id, '', 2))

return JSON.stringify(id, '', 2)
})())
}
}
2 changes: 1 addition & 1 deletion test/cli/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('config', () => runOnAndOff((thing) => {
})

it('set a config key with invalid json', () => {
return ipfs.fail('config foo {"bar:0} --json')
return ipfs.fail('config foo {"bar:0"} --json')
})

it('get a config key value', () => {
Expand Down

0 comments on commit b9836a2

Please sign in to comment.