pulumi/cmd/env_ls.go
Matt Ellis 7900e2edb1 Move environment printing back into the CLI
Previously the engine was concerned with displaying information about
the environment. Now the engine returns an environment info object
which the CLI uses to display environment information.
2017-10-02 13:34:33 -07:00

45 lines
1.1 KiB
Go

// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
package cmd
import (
"fmt"
"strconv"
"github.com/spf13/cobra"
"github.com/pulumi/pulumi/pkg/util/cmdutil"
)
func newEnvLsCmd() *cobra.Command {
return &cobra.Command{
Use: "ls",
Short: "List all known environments",
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
envs, err := lumiEngine.GetEnvironments()
if err != nil {
return err
}
fmt.Printf("%-20s %-48s %-12s\n", "NAME", "LAST UPDATE", "RESOURCE COUNT")
for _, env := range envs {
// Now print out the name, last deployment time (if any), and resources (if any).
lastDeploy := "n/a"
resourceCount := "n/a"
if env.Checkpoint.Latest != nil {
lastDeploy = env.Checkpoint.Latest.Time.String()
}
if env.Snapshot != nil {
resourceCount = strconv.Itoa(len(env.Snapshot.Resources))
}
display := env.Name
if env.IsCurrent {
display += "*" // fancify the current environment.
}
fmt.Printf("%-20s %-48s %-12s\n", display, lastDeploy, resourceCount)
}
return nil
}),
}
}