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

Commit 308b9a4

Browse files
committed
fix: use only one yargs instance
1 parent 563034e commit 308b9a4

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/cli/bin.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ const mfs = require('ipfs-mfs/cli')
1111
const debug = require('debug')('ipfs:cli')
1212
const pkg = require('../../package.json')
1313

14-
function globalOptions (args) {
15-
return yargs(args)
14+
async function main (args) {
15+
const oneWeek = 1000 * 60 * 60 * 24 * 7
16+
updateNotifier({ pkg, updateCheckInterval: oneWeek }).notify()
17+
18+
const cli = yargs(args)
1619
.option('silent', {
1720
desc: 'Write no output',
1821
type: 'boolean',
@@ -33,35 +36,34 @@ function globalOptions (args) {
3336
if (err) {
3437
throw err // preserve stack
3538
}
39+
3640
if (args.length > 0) {
3741
print(msg)
3842
}
43+
3944
yargs.showHelp()
4045
})
41-
}
4246

43-
async function main (args) {
44-
const oneWeek = 1000 * 60 * 60 * 24 * 7
45-
updateNotifier({ pkg, updateCheckInterval: oneWeek }).notify()
46-
47-
const cli = globalOptions(args)
48-
49-
// Function to get hold of a singleton ipfs instance
50-
const getIpfs = utils.singleton(cb => utils.getIPFS(globalOptions(args).argv, cb))
47+
let getIpfs = null
5148

5249
// add MFS (Files API) commands
5350
mfs(cli)
5451

5552
cli
5653
.commandDir('commands')
54+
.middleware(argv => {
55+
// Function to get hold of a singleton ipfs instance
56+
getIpfs = argv.getIpfs = utils.singleton(cb => utils.getIPFS(argv, cb))
57+
return argv
58+
})
5759
.help()
5860
.strict()
5961
.completion()
6062

6163
let exitCode = 0
6264

6365
try {
64-
const { data } = await new YargsPromise(cli, { getIpfs }).parse(args)
66+
const { data } = await new YargsPromise(cli).parse(args)
6567
if (data) print(data)
6668
} catch (err) {
6769
debug(err)

0 commit comments

Comments
 (0)