Skip to content

Commit 82e736f

Browse files
committed
✨ Add global sub-command support
1 parent 2ad44d9 commit 82e736f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/completion.ps1

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,22 @@
22
Register-ArgumentCompleter -Native -CommandName $_ -ScriptBlock {
33
param($wordToComplete, $commandAst, $cursorPosition)
44

5-
. $PSScriptRoot\commands.ps1
5+
$subCommand = $commandAst.CommandElements[1].Value
6+
7+
switch ($subCommand) {
8+
'global' {
9+
. $PSScriptRoot\sub-commands\global.ps1
10+
}
11+
Default {
12+
. $PSScriptRoot\commands.ps1
13+
14+
# Don't complete any word after sub-command when it isn't one of above commands.
15+
if ($subCommand -in $cmds) {
16+
$cmds = @()
17+
}
18+
}
19+
}
20+
621
$cmds |
722
Where-Object { $_ -like "$wordToComplete*" } |
823
Sort-Object |

src/sub-commands/global.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
$cmds = @(
2+
'add',
3+
'bin',
4+
'list',
5+
'remove',
6+
'upgrade',
7+
'upgrade-interactive'
8+
)

0 commit comments

Comments
 (0)