Files

62 lines
1.2 KiB
Go

package cmd
import (
"fmt"
"os"
"text/tabwriter"
"github.com/spf13/cobra"
)
var kmdListCmd = &cobra.Command{
Use: "list",
Short: "List all stacks from Komodo Core",
Long: `Retrieves all stacks from Komodo along with their runtime status, git provider, repo, and webhook configuration.`,
RunE: func(cmd *cobra.Command, args []string) error {
client, err := getKomodoClient()
if err != nil {
return err
}
stacks, err := client.ListStacksWithDetails()
if err != nil {
return fmt.Errorf("failed to retrieve stacks from Komodo: %w", err)
}
if len(stacks) == 0 {
fmt.Println("No stacks found.")
return nil
}
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
noHeader, _ := cmd.Flags().GetBool("no-header")
if !noHeader {
fmt.Fprintln(w, "NAME\tSERVER\tSTATUS\tPROVIDER\tREPO\tWEBHOOK")
fmt.Fprintln(w, "----\t------\t------\t--------\t----\t-------")
}
for _, s := range stacks {
webhookStatus := "disabled"
if s.WebhookEnabled {
webhookStatus = "enabled"
}
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\n",
s.Name,
s.Server,
s.Status,
s.GitProvider,
s.Repo,
webhookStatus,
)
}
return w.Flush()
},
}
func init() {
kmdCmd.AddCommand(kmdListCmd)
}