Centralise adapter types
Since the generic commands tend to share a few of the methods they need -- at least AsClientObject -- it's worth having just one wrapper struct for each API type, and adding methods to it where necessary. For the automation types, I put these in auto.go. While doing this I also did some tidying: - I changed the name of the wrappers to `<type>Adapter`, and the generic adapter to `universalAdapter` (it's only needed for delete, so far). - I de-exported and renamed some interface methods e.g., `exportItem`. They aren't needed outside the package. Signed-off-by: Michael Bridgen <michael@weave.works>
This commit is contained in:
@@ -45,10 +45,10 @@ func init() {
|
||||
}
|
||||
|
||||
type summarisable interface {
|
||||
objectContainer
|
||||
Len() int
|
||||
SummariseAt(i int, includeNamespace bool) []string
|
||||
Headers(includeNamespace bool) []string
|
||||
adapter
|
||||
len() int
|
||||
summariseItem(i int, includeNamespace bool) []string
|
||||
headers(includeNamespace bool) []string
|
||||
}
|
||||
|
||||
// --- these help with implementations of summarisable
|
||||
@@ -92,20 +92,20 @@ func (get getCommand) run(cmd *cobra.Command, args []string) error {
|
||||
if !allNamespaces {
|
||||
listOpts = append(listOpts, client.InNamespace(namespace))
|
||||
}
|
||||
err = kubeClient.List(ctx, get.list.AsClientObject(), listOpts...)
|
||||
err = kubeClient.List(ctx, get.list.asRuntimeObject(), listOpts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if get.list.Len() == 0 {
|
||||
if get.list.len() == 0 {
|
||||
logger.Failuref("no imagerepository objects found in %s namespace", namespace)
|
||||
return nil
|
||||
}
|
||||
|
||||
header := get.list.Headers(allNamespaces)
|
||||
header := get.list.headers(allNamespaces)
|
||||
var rows [][]string
|
||||
for i := 0; i < get.list.Len(); i++ {
|
||||
row := get.list.SummariseAt(i, allNamespaces)
|
||||
for i := 0; i < get.list.len(); i++ {
|
||||
row := get.list.summariseItem(i, allNamespaces)
|
||||
rows = append(rows, row)
|
||||
}
|
||||
utils.PrintTable(os.Stdout, header, rows)
|
||||
|
||||
Reference in New Issue
Block a user