File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 3
3
package main
4
4
5
5
import (
6
+ "errors"
6
7
"fmt"
7
8
"os"
8
9
"runtime"
@@ -12,6 +13,21 @@ import (
12
13
"github.com/spf13/cobra"
13
14
)
14
15
16
+ func printShellCompletion (cmd * cobra.Command , command string ) error {
17
+ switch command {
18
+ case "bash" :
19
+ return cmd .GenBashCompletionV2 (os .Stdout , true )
20
+ case "zsh" :
21
+ return cmd .GenZshCompletion (os .Stdout )
22
+ case "fish" :
23
+ return cmd .GenFishCompletion (os .Stdout , true )
24
+ case "powershell" :
25
+ return cmd .GenPowerShellCompletion (os .Stdout )
26
+ default :
27
+ return errors .New ("Unknown shell: " + command )
28
+ }
29
+ }
30
+
15
31
//go:generate go run scripts/include.go
16
32
func main () {
17
33
// f, _ := os.Create("scc.pprof")
@@ -426,6 +442,17 @@ func main() {
426
442
"set currency symbol" ,
427
443
)
428
444
445
+ // If invoked in the format of "scc completion --shell [name of shell]", generate command line completions instead.
446
+ // With the --shell option, unintentionally triggering shell completions should be highly unlikely.
447
+ args := os .Args
448
+ if len (args ) == 4 && args [1 ] == "completion" && args [2 ] == "--shell" {
449
+ err := printShellCompletion (rootCmd , args [3 ])
450
+ if err != nil {
451
+ fmt .Printf ("Error printing shell completion: %s\n " , err )
452
+ }
453
+ return
454
+ }
455
+
429
456
if err := rootCmd .Execute (); err != nil {
430
457
os .Exit (1 )
431
458
}
You can’t perform that action at this time.
0 commit comments