pulumi/cmd/stack_ls.go
Matt Ellis 07b4d9b36b Add Pulumi.com backend, unify cobra Commands
As part of the unification it became clear where we did not support
features that we had for the local backend. I opened issues and added
comments.
2017-11-02 11:19:00 -07:00

43 lines
990 B
Go

// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
package cmd
import (
"fmt"
"github.com/pulumi/pulumi/pkg/tokens"
"github.com/spf13/cobra"
"github.com/pulumi/pulumi/pkg/util/cmdutil"
)
func newStackLsCmd() *cobra.Command {
return &cobra.Command{
Use: "ls",
Short: "List all known stacks",
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
currentStack, err := getCurrentStack()
if err != nil {
// If we couldn't figure out the current stack, just don't print the '*' later
// on instead of failing.
currentStack = tokens.QName("")
}
summaries, err := backend.GetStacks()
if err != nil {
return err
}
fmt.Printf("%-20s %-48s %-12s\n", "NAME", "LAST UPDATE", "RESOURCE COUNT")
for _, stack := range summaries {
if stack.Name == currentStack {
stack.Name += "*"
}
fmt.Printf("%-20s %-48s %-12s\n", stack.Name, stack.LastDeploy, stack.ResourceCount)
}
return nil
}),
}
}