Skip to content

Commit

Permalink
Merge pull request #215 from stefanprodan/list-resources
Browse files Browse the repository at this point in the history
Use tabular view for `timoni inspect resources`
  • Loading branch information
stefanprodan authored Oct 11, 2023
2 parents 870f0ad + c5a284f commit 646d3d5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
30 changes: 26 additions & 4 deletions cmd/timoni/inspect_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ package main
import (
"context"
"fmt"
"strings"

"github.com/fluxcd/pkg/ssa"
"github.com/spf13/cobra"

"github.com/stefanprodan/timoni/internal/runtime"
)

Expand Down Expand Up @@ -74,14 +75,35 @@ func runInspectResourcesCmd(cmd *cobra.Command, args []string) error {

iManager := runtime.InstanceManager{Instance: *inst}

metas, err := iManager.ListMeta()
//metas, err := iManager.ListMeta()
//if err != nil {
// return err
//}
//
//for _, meta := range metas {
// fmt.Fprintln(cmd.OutOrStdout(), colorizeSubject(ssa.FmtObjMetadata(meta)))
//}

objects, err := iManager.ListObjects()
if err != nil {
return err
}

for _, meta := range metas {
fmt.Fprintln(cmd.OutOrStdout(), colorizeSubject(ssa.FmtObjMetadata(meta)))
var rows [][]string
for _, obj := range objects {
ns := "-"
if obj.GetNamespace() != "" {
ns = obj.GetNamespace()
}
row := []string{
strings.ToLower(obj.GetKind() + "/" + obj.GetName()),
ns,
obj.GetAPIVersion(),
}
rows = append(rows, row)
}

printTable(rootCmd.OutOrStdout(), []string{"name", "namespace", "API version"}, rows)

return nil
}
4 changes: 2 additions & 2 deletions cmd/timoni/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func TestInspect(t *testing.T) {
g.Expect(err).ToNot(HaveOccurred())

// Verify inspect output contains the expected resources
g.Expect(output).To(ContainSubstring(fmt.Sprintf("ConfigMap/%s/%s-client", namespace, name)))
g.Expect(output).To(ContainSubstring(fmt.Sprintf("ConfigMap/%s/%s-server", namespace, name)))
g.Expect(output).To(ContainSubstring(fmt.Sprintf("configmap/%s-client", name)))
g.Expect(output).To(ContainSubstring(fmt.Sprintf("configmap/%s-server", name)))
})
}

Expand Down

0 comments on commit 646d3d5

Please sign in to comment.