@@ -67,8 +67,8 @@ func setPluginsFlag(value string) {
67
67
setFlag (pluginsFlag , value )
68
68
}
69
69
70
- func hasSubCommand (c * CLI , name string ) bool {
71
- for _ , subcommand := range c . cmd .Commands () {
70
+ func hasSubCommand (cmd * cobra. Command , name string ) bool {
71
+ for _ , subcommand := range cmd .Commands () {
72
72
if subcommand .Name () == name {
73
73
return true
74
74
}
@@ -677,15 +677,15 @@ var _ = Describe("CLI", func() {
677
677
const version = "version string"
678
678
c , err = New (WithVersion (version ))
679
679
Expect (err ).NotTo (HaveOccurred ())
680
- Expect (hasSubCommand (c , "version" )).To (BeTrue ())
680
+ Expect (hasSubCommand (c . cmd , "version" )).To (BeTrue ())
681
681
})
682
682
})
683
683
684
684
When ("enabling completion" , func () {
685
685
It ("should create a valid CLI" , func () {
686
686
c , err = New (WithCompletion ())
687
687
Expect (err ).NotTo (HaveOccurred ())
688
- Expect (hasSubCommand (c , "completion" )).To (BeTrue ())
688
+ Expect (hasSubCommand (c . cmd , "completion" )).To (BeTrue ())
689
689
})
690
690
})
691
691
@@ -712,22 +712,43 @@ var _ = Describe("CLI", func() {
712
712
})
713
713
714
714
When ("providing extra commands" , func () {
715
- var extraCommand * cobra.Command
716
-
717
715
It ("should create a valid CLI for non-conflicting ones" , func () {
718
- extraCommand = & cobra.Command {Use : "extra" }
716
+ extraCommand : = & cobra.Command {Use : "extra" }
719
717
c , err = New (WithExtraCommands (extraCommand ))
720
718
Expect (err ).NotTo (HaveOccurred ())
721
- Expect (hasSubCommand (c , extraCommand .Use )).To (BeTrue ())
719
+ Expect (hasSubCommand (c . cmd , extraCommand .Use )).To (BeTrue ())
722
720
})
723
721
724
722
It ("should return an error for conflicting ones" , func () {
725
- extraCommand = & cobra.Command {Use : "init" }
723
+ extraCommand : = & cobra.Command {Use : "init" }
726
724
_ , err = New (WithExtraCommands (extraCommand ))
727
725
Expect (err ).To (HaveOccurred ())
728
726
})
729
727
})
730
728
729
+ When ("providing extra alpha commands" , func () {
730
+ It ("should create a valid CLI for non-conflicting ones" , func () {
731
+ extraAlphaCommand := & cobra.Command {Use : "extra" }
732
+ c , err = New (WithExtraAlphaCommands (extraAlphaCommand ))
733
+ Expect (err ).NotTo (HaveOccurred ())
734
+ var alpha * cobra.Command
735
+ for _ , subcmd := range c .cmd .Commands () {
736
+ if subcmd .Name () == alphaCommand {
737
+ alpha = subcmd
738
+ break
739
+ }
740
+ }
741
+ Expect (alpha ).NotTo (BeNil ())
742
+ Expect (hasSubCommand (alpha , extraAlphaCommand .Use )).To (BeTrue ())
743
+ })
744
+
745
+ It ("should return an error for conflicting ones" , func () {
746
+ extraAlphaCommand := & cobra.Command {Use : "extra" }
747
+ _ , err = New (WithExtraAlphaCommands (extraAlphaCommand , extraAlphaCommand ))
748
+ Expect (err ).To (HaveOccurred ())
749
+ })
750
+ })
751
+
731
752
When ("providing deprecated plugins" , func () {
732
753
It ("should succeed and print the deprecation notice" , func () {
733
754
const (
0 commit comments