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

Commit c649a98

Browse files
committed
fix: resolve conflits with the new inline requires
1 parent 6dbb834 commit c649a98

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

src/cli/bin.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
'use strict'
44

5+
const fs = require('fs')
6+
const path = require('path')
57
const yargs = require('yargs/yargs')
68
const updateNotifier = require('update-notifier')
79
const readPkgUp = require('read-pkg-up')
@@ -18,16 +20,16 @@ updateNotifier({
1820
}).notify()
1921

2022
const MSG_USAGE = `Usage:
21-
ipfs - Global p2p merkle-dag filesystem.
23+
ipfs - Global p2p merkle-dag filesystem.
2224
2325
ipfs [options] <command> ...`
24-
const MSG_EPILOGUE = `Use 'ipfs <command> --help' to learn more about each command.
26+
const MSG_EPILOGUE = `Use 'ipfs <command> --help' to learn more about each command.
2527
2628
ipfs uses a repository in the local file system. By default, the repo is
2729
located at ~/.ipfs. To change the repo location, set the $IPFS_PATH
2830
environment variable:
2931
30-
export IPFS_PATH=/path/to/ipfsrepo
32+
export IPFS_PATH=/path/to/ipfsrepo
3133
3234
EXIT STATUS
3335
@@ -39,6 +41,9 @@ The CLI will exit with one of the following values:
3941
const MSG_NO_CMD = 'You need at least one command before moving on'
4042

4143
const argv = process.argv.slice(2)
44+
const commandNames = fs.readdirSync(path.join(__dirname, 'commands'))
45+
const isCommand = commandNames.includes(`${argv[0]}.js`)
46+
4247
let args = {}
4348
let cli = yargs(argv)
4449
.usage(MSG_USAGE)
@@ -63,13 +68,25 @@ let cli = yargs(argv)
6368
desc: 'Use a specific API instance.',
6469
type: 'string'
6570
})
66-
.commandDir('commands')
67-
// NOTE: This creates an alias of
68-
// `jsipfs files {add, get, cat}` to `jsipfs {add, get, cat}`.
69-
// This will stay until https://github.com/ipfs/specs/issues/98 is resolved.
70-
.command(addCmd)
71-
.command(catCmd)
72-
.command(getCmd)
71+
.commandDir('commands', {
72+
// Only include the commands for the sub-system we're using, or include all
73+
// if no sub-system command has been passed.
74+
include (path, filename) {
75+
if (!isCommand) return true
76+
return `${argv[0]}.js` === filename
77+
}
78+
})
79+
80+
if(!isCommand){
81+
cli
82+
// NOTE: This creates an alias of
83+
// `jsipfs files {add, get, cat}` to `jsipfs {add, get, cat}`.
84+
// This will stay until https://github.com/ipfs/specs/issues/98 is resolved.
85+
.command(addCmd)
86+
.command(catCmd)
87+
.command(getCmd)
88+
}
89+
cli
7390
.demandCommand(1, MSG_NO_CMD)
7491
.alias('help', 'h')
7592
.epilogue(MSG_EPILOGUE)

src/cli/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ exports.getNodeOrAPI = (argv, stateOptions = {forceInitialized: true}) => {
4444
return Promise.resolve(getAPICtl(argv.api))
4545
}
4646

47-
const {createNodePromise} = require('../core')
47+
const IPFS = require('../core')
4848
return IPFS.createNodePromise({
4949
repo: exports.getRepoPath(),
5050
init: false,

0 commit comments

Comments
 (0)