@@ -17,6 +17,7 @@ module.exports = function completion (yargs, usage, command) {
17
17
const current = args . length ? args [ args . length - 1 ] : ''
18
18
const argv = yargs . parse ( args , true )
19
19
const aliases = yargs . parsed . aliases
20
+ const parentCommands = yargs . getContext ( ) . commands
20
21
21
22
// a custom completion function can be provided
22
23
// to completion().
@@ -55,7 +56,7 @@ module.exports = function completion (yargs, usage, command) {
55
56
}
56
57
}
57
58
58
- if ( ! current . match ( / ^ - / ) ) {
59
+ if ( ! current . match ( / ^ - / ) && parentCommands [ parentCommands . length - 1 ] !== current ) {
59
60
usage . getCommands ( ) . forEach ( ( usageCommand ) => {
60
61
const commandName = command . parseCommand ( usageCommand [ 0 ] ) . cmd
61
62
if ( args . indexOf ( commandName ) === - 1 ) {
@@ -69,7 +70,7 @@ module.exports = function completion (yargs, usage, command) {
69
70
} )
70
71
}
71
72
72
- if ( current . match ( / ^ - / ) ) {
73
+ if ( current . match ( / ^ - / ) || ( current === '' && completions . length === 0 ) ) {
73
74
const descs = usage . getDescriptions ( )
74
75
Object . keys ( yargs . getOptions ( ) . key ) . forEach ( ( key ) => {
75
76
// If the key and its aliases aren't in 'args', add the key to 'completions'
@@ -80,7 +81,7 @@ module.exports = function completion (yargs, usage, command) {
80
81
completions . push ( `--${ key } ` )
81
82
} else {
82
83
const desc = descs [ key ] || ''
83
- completions . push ( `--${ key . replace ( / : / g, '\\:' ) } :${ desc } ` )
84
+ completions . push ( `--${ key . replace ( / : / g, '\\:' ) } :${ desc . replace ( '__yargsString__:' , '' ) } ` )
84
85
}
85
86
}
86
87
} )
0 commit comments