@@ -6,10 +6,9 @@ import (
66
77	"github.com/spf13/cobra" 
88
9- 	operatorsv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v1" 
10- 
119	"github.com/operator-framework/kubectl-operator/internal/cmd/internal/log" 
1210	"github.com/operator-framework/kubectl-operator/internal/pkg/action" 
11+ 	"github.com/operator-framework/kubectl-operator/internal/pkg/operator" 
1312)
1413
1514var  (
@@ -43,22 +42,17 @@ func newOperatorDescribeCmd(cfg *action.Configuration) *cobra.Command {
4342			// Find the package manifest and package channel for the operator 
4443			pms , err  :=  l .Run (cmd .Context ())
4544			if  err  !=  nil  {
46- 				log .Fatalf ( "failed to find operator: %v" ,  err )
45+ 				log .Fatal ( err )
4746			}
4847
4948			// we only expect one item because describe always searches 
5049			// for a specific operator by name 
51- 			pm  :=  & pms [0 ]
52- 
53- 			// If the user asked for a channel, look for that 
54- 			if  channel  ==  ""  {
55- 				channel  =  pm .Status .DefaultChannel 
56- 			}
50+ 			pm  :=  pms [0 ]
5751
58- 			pc , err  :=  getPackageChannel (channel ,  pm )
52+ 			pc , err  :=  pm . GetChannel (channel )
5953			if  err  !=  nil  {
6054				// the requested channel doesn't exist 
61- 				log .Fatalf ( "failed to find channel for operator: %v" ,  err )
55+ 				log .Fatal ( err )
6256			}
6357
6458			// prepare what we want to print to the console 
@@ -78,10 +72,10 @@ func newOperatorDescribeCmd(cfg *action.Configuration) *cobra.Command {
7872				catHdr + fmt .Sprintf ("%s\n \n " , pm .Status .CatalogSourceDisplayName ),
7973				// available channels 
8074				chHdr + fmt .Sprintf ("%s\n \n " ,
81- 					strings .Join (getAvailableChannelsWithMarkers (channel , pm ), "\n " )),
75+ 					strings .Join (getAvailableChannelsWithMarkers (* pc , pm ), "\n " )),
8276				// install modes 
8377				imHdr + fmt .Sprintf ("%s\n \n " ,
84- 					strings .Join (getSupportedInstallModes ( pc ), "\n " )),
78+ 					strings .Join (pc . GetSupportedInstallModes (). List ( ), "\n " )),
8579				// description 
8680				sdHdr + fmt .Sprintf ("%s\n " ,
8781					pc .CurrentCSVDesc .Annotations [descAnnot ]),
@@ -102,8 +96,9 @@ func newOperatorDescribeCmd(cfg *action.Configuration) *cobra.Command {
10296	}
10397
10498	// add flags to the flagset for this command. 
105- 	cmd .Flags ().StringVarP (& channel , "channel" , "c" , "" , "channel" )
106- 	cmd .Flags ().BoolVarP (& longDescription , "with-long-description" , "L" , false , "long description" )
99+ 	bindOperatorListAvailableFlags (cmd .Flags (), l )
100+ 	cmd .Flags ().StringVarP (& channel , "channel" , "C" , "" , "package channel to describe" )
101+ 	cmd .Flags ().BoolVarP (& longDescription , "with-long-description" , "L" , false , "include long description" )
107102
108103	return  cmd 
109104}
@@ -114,45 +109,17 @@ func asHeader(s string) string {
114109	return  fmt .Sprintf ("== %s ==\n " , s )
115110}
116111
117- // getPackageChannel returns the package channel specified, or the default if none was specified. 
118- func  getPackageChannel (channel  string , pm  * operatorsv1.PackageManifest ) (* operatorsv1.PackageChannel , error ) {
119- 	var  packageChannel  * operatorsv1.PackageChannel 
120- 	for  _ , ch  :=  range  pm .Status .Channels  {
121- 		ch  :=  ch 
122- 		if  ch .Name  ==  channel  {
123- 			packageChannel  =  & ch 
124- 		}
125- 	}
126- 	if  packageChannel  ==  nil  {
127- 		return  nil , fmt .Errorf ("channel %q does not exist for package %q" , channel , pm .GetName ())
128- 	}
129- 	return  packageChannel , nil 
130- }
131- 
132- // GetSupportedInstallModes returns a string slice representation of install mode 
133- // objects the operator supports. 
134- func  getSupportedInstallModes (pc  * operatorsv1.PackageChannel ) []string  {
135- 	supportedInstallModes  :=  make ([]string , 1 )
136- 	for  _ , imode  :=  range  pc .CurrentCSVDesc .InstallModes  {
137- 		if  imode .Supported  {
138- 			supportedInstallModes  =  append (supportedInstallModes , string (imode .Type ))
139- 		}
140- 	}
141- 
142- 	return  supportedInstallModes 
143- }
144- 
145112// getAvailableChannelsWithMarkers parses all available package channels for a package manifest 
146113// and returns those channel names with indicators for pretty-printing whether they are shown 
147114// or the default channel 
148- func  getAvailableChannelsWithMarkers (channel  string , pm  * operatorsv1 .PackageManifest ) []string  {
115+ func  getAvailableChannelsWithMarkers (channel  operator. PackageChannel , pm  operator .PackageManifest ) []string  {
149116	channels  :=  make ([]string , len (pm .Status .Channels ))
150117	for  i , ch  :=  range  pm .Status .Channels  {
151118		n  :=  ch .Name 
152- 		if  ch .IsDefaultChannel (* pm ) {
119+ 		if  ch .IsDefaultChannel (pm . PackageManifest ) {
153120			n  +=  " (default)" 
154121		}
155- 		if  channel  ==  ch .Name  {
122+ 		if  channel . Name  ==  ch .Name  {
156123			n  +=  " (shown)" 
157124		}
158125		channels [i ] =  n 
0 commit comments