2
2
3
3
'use strict'
4
4
5
+ const fs = require ( 'fs' )
6
+ const path = require ( 'path' )
5
7
const yargs = require ( 'yargs/yargs' )
6
8
const updateNotifier = require ( 'update-notifier' )
7
9
const readPkgUp = require ( 'read-pkg-up' )
@@ -18,16 +20,16 @@ updateNotifier({
18
20
} ) . notify ( )
19
21
20
22
const MSG_USAGE = `Usage:
21
- ipfs - Global p2p merkle-dag filesystem.
23
+ ipfs - Global p2p merkle-dag filesystem.
22
24
23
25
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.
25
27
26
28
ipfs uses a repository in the local file system. By default, the repo is
27
29
located at ~/.ipfs. To change the repo location, set the $IPFS_PATH
28
30
environment variable:
29
31
30
- export IPFS_PATH=/path/to/ipfsrepo
32
+ export IPFS_PATH=/path/to/ipfsrepo
31
33
32
34
EXIT STATUS
33
35
@@ -39,6 +41,9 @@ The CLI will exit with one of the following values:
39
41
const MSG_NO_CMD = 'You need at least one command before moving on'
40
42
41
43
const argv = process . argv . slice ( 2 )
44
+ const commandNames = fs . readdirSync ( path . join ( __dirname , 'commands' ) )
45
+ const isCommand = commandNames . includes ( `${ argv [ 0 ] } .js` )
46
+
42
47
let args = { }
43
48
let cli = yargs ( argv )
44
49
. usage ( MSG_USAGE )
@@ -63,13 +68,25 @@ let cli = yargs(argv)
63
68
desc : 'Use a specific API instance.' ,
64
69
type : 'string'
65
70
} )
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
73
90
. demandCommand ( 1 , MSG_NO_CMD )
74
91
. alias ( 'help' , 'h' )
75
92
. epilogue ( MSG_EPILOGUE )
0 commit comments