File tree Expand file tree Collapse file tree 4 files changed +50
-0
lines changed Expand file tree Collapse file tree 4 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -462,3 +462,8 @@ func (c CLI) metadata() plugin.CLIMetadata {
462
462
func (c CLI ) Run () error {
463
463
return c .cmd .Execute ()
464
464
}
465
+
466
+ // Command returns the underlying root command.
467
+ func (c CLI ) Command () * cobra.Command {
468
+ return c .cmd
469
+ }
Original file line number Diff line number Diff line change @@ -600,5 +600,14 @@ plugins:
600
600
fmt .Sprintf (noticeColor , fmt .Sprintf (deprecationFmt , deprecationWarning ))))
601
601
})
602
602
})
603
+
604
+ When ("new succeeds" , func () {
605
+ It ("should return the underlying command" , func () {
606
+ c , err = New ()
607
+ Expect (err ).NotTo (HaveOccurred ())
608
+ Expect (c .Command ()).NotTo (BeNil ())
609
+ Expect (c .Command ()).To (Equal (c .cmd ))
610
+ })
611
+ })
603
612
})
604
613
})
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ import (
31
31
32
32
"sigs.k8s.io/kubebuilder/v4/pkg/config"
33
33
cfgv3 "sigs.k8s.io/kubebuilder/v4/pkg/config/v3"
34
+ "sigs.k8s.io/kubebuilder/v4/pkg/machinery"
34
35
"sigs.k8s.io/kubebuilder/v4/pkg/plugin"
35
36
"sigs.k8s.io/kubebuilder/v4/pkg/plugins/external"
36
37
)
@@ -152,6 +153,18 @@ func WithCompletion() Option {
152
153
}
153
154
}
154
155
156
+ // WithFilesystem is an Option that allows to set the filesystem used in the CLI.
157
+ func WithFilesystem (fs machinery.Filesystem ) Option {
158
+ return func (c * CLI ) error {
159
+ if fs .FS == nil {
160
+ return errors .New ("invalid filesystem" )
161
+ }
162
+
163
+ c .fs = fs
164
+ return nil
165
+ }
166
+ }
167
+
155
168
// parseExternalPluginArgs returns the program arguments.
156
169
func parseExternalPluginArgs () (args []string ) {
157
170
// Loop through os.Args and only get flags and their values that should be passed to the plugins
Original file line number Diff line number Diff line change @@ -717,4 +717,27 @@ var _ = Describe("CLI options", func() {
717
717
Expect (c .completionCommand ).To (BeTrue ())
718
718
})
719
719
})
720
+
721
+ Context ("WithFilesystem" , func () {
722
+ When ("providing a valid filesystem" , func () {
723
+ It ("should use the provided filesystem" , func () {
724
+ fs := machinery.Filesystem {
725
+ FS : afero .NewMemMapFs (),
726
+ }
727
+ c , err = newCLI (WithFilesystem (fs ))
728
+ Expect (err ).NotTo (HaveOccurred ())
729
+ Expect (c ).NotTo (BeNil ())
730
+ Expect (c .fs ).To (Equal (fs ))
731
+ })
732
+ })
733
+
734
+ When ("providing a invalid filesystem" , func () {
735
+ It ("should return an error" , func () {
736
+ fs := machinery.Filesystem {}
737
+ c , err = newCLI (WithFilesystem (fs ))
738
+ Expect (err ).To (HaveOccurred ())
739
+ Expect (c ).To (BeNil ())
740
+ })
741
+ })
742
+ })
720
743
})
You can’t perform that action at this time.
0 commit comments