@@ -30,7 +30,7 @@ func GetRunner(factory cmdutil.Factory, invFactory inventory.ClientFactory, load
3030 r := & Runner {
3131 factory : factory ,
3232 invFactory : invFactory ,
33- loader : loader ,
33+ loader : NewInventoryLoader ( loader ) ,
3434 pollerFactoryFunc : pollerFactoryFunc ,
3535 }
3636 c := & cobra.Command {
@@ -59,7 +59,7 @@ type Runner struct {
5959 Command * cobra.Command
6060 factory cmdutil.Factory
6161 invFactory inventory.ClientFactory
62- loader manifestreader. ManifestLoader
62+ loader Loader
6363
6464 period time.Duration
6565 pollUntil string
@@ -73,26 +73,11 @@ type Runner struct {
7373// poller to compute status for each of the resources. One of the printer
7474// implementations takes care of printing the output.
7575func (r * Runner ) runE (cmd * cobra.Command , args []string ) error {
76- _ , err := common .DemandOneDirectory (args )
77- if err != nil {
78- return err
79- }
80-
81- reader , err := r .loader .ManifestReader (cmd .InOrStdin (), flagutils .PathFromArgs (args ))
82- if err != nil {
83- return err
84- }
85- objs , err := reader .Read ()
76+ inv , err := r .loader .GetInvInfo (cmd , args )
8677 if err != nil {
8778 return err
8879 }
8980
90- invObj , _ , err := inventory .SplitUnstructureds (objs )
91- if err != nil {
92- return err
93- }
94- inv := inventory .WrapInventoryInfoObj (invObj )
95-
9681 invClient , err := r .invFactory .NewClient (r .factory )
9782 if err != nil {
9883 return err
@@ -207,3 +192,40 @@ func allKnownNotifierFunc(cancelFunc context.CancelFunc) collector.ObserverFunc
207192func pollerFactoryFunc (f cmdutil.Factory ) (poller.Poller , error ) {
208193 return polling .NewStatusPollerFromFactory (f , polling.Options {})
209194}
195+
196+ type Loader interface {
197+ GetInvInfo (cmd * cobra.Command , args []string ) (inventory.Info , error )
198+ }
199+
200+ type InventoryLoader struct {
201+ Loader manifestreader.ManifestLoader
202+ }
203+
204+ func NewInventoryLoader (loader manifestreader.ManifestLoader ) * InventoryLoader {
205+ return & InventoryLoader {
206+ Loader : loader ,
207+ }
208+ }
209+
210+ func (ir * InventoryLoader ) GetInvInfo (cmd * cobra.Command , args []string ) (inventory.Info , error ) {
211+ _ , err := common .DemandOneDirectory (args )
212+ if err != nil {
213+ return nil , err
214+ }
215+
216+ reader , err := ir .Loader .ManifestReader (cmd .InOrStdin (), flagutils .PathFromArgs (args ))
217+ if err != nil {
218+ return nil , err
219+ }
220+ objs , err := reader .Read ()
221+ if err != nil {
222+ return nil , err
223+ }
224+
225+ invObj , _ , err := inventory .SplitUnstructureds (objs )
226+ if err != nil {
227+ return nil , err
228+ }
229+ inv := inventory .WrapInventoryInfoObj (invObj )
230+ return inv , nil
231+ }
0 commit comments