ls

package
v1.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Example (Ls_help)
package main

import (
	"os"

	"github.com/aws-cloudformation/rain/internal/cmd/ls"
)

func main() {
	os.Args = []string{
		os.Args[0],
		"--help",
	}

	ls.Cmd.Execute()
}
Output:

Displays a list of all running stacks or the contents of <stack> if provided.

Usage:
  ls <stack>

Aliases:
  ls, list

Flags:
  -a, --all    list stacks in all regions; if you specify a stack, show more details
  -h, --help   help for ls

Index

Examples

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:                   "ls <stack>",
	Short:                 "List running CloudFormation stacks",
	Long:                  "Displays a list of all running stacks or the contents of <stack> if provided.",
	Args:                  cobra.MaximumNArgs(1),
	Aliases:               []string{"list"},
	DisableFlagsInUseLine: true,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 1 {
			stackName := args[0]

			spinner.Push("Fetching stack status")
			stack, err := cfn.GetStack(stackName)
			if err != nil {
				panic(ui.Errorf(err, "failed to list stack '%s'", stackName))
			}

			output := cfn.GetStackSummary(stack, all)
			spinner.Pop()

			fmt.Println(output)
		} else {
			var err error
			regions := []string{aws.Config().Region}

			if all {
				spinner.Push("Fetching region list")
				regions, err = ec2.GetRegions()
				if err != nil {
					panic(ui.Errorf(err, "unable to get region list"))
				}
				spinner.Pop()
			}

			origRegion := aws.Config().Region

			for _, region := range regions {
				spinner.Push(fmt.Sprintf("Fetching stacks in %s", region))
				aws.SetRegion(region)
				stacks, err := cfn.ListStacks()
				if err != nil {
					panic(ui.Errorf(err, "failed to list stacks"))
				}
				spinner.Pop()

				if len(stacks) == 0 && all {
					continue
				}

				stackNames := make(sort.StringSlice, 0)
				stackMap := make(map[string]types.StackSummary)
				for _, stack := range stacks {
					stackNames = append(stackNames, *stack.StackName)
					stackMap[*stack.StackName] = stack
				}
				sort.Strings(stackNames)

				fmt.Println(console.Yellow(fmt.Sprintf("CloudFormation stacks in %s:", region)))
				for _, stackName := range stackNames {
					stack := stackMap[stackName]

					if stack.ParentId == nil {
						fmt.Println(ui.Indent("  ", formatStack(stack, stackMap)))
					}
				}
			}

			aws.SetRegion(origRegion)
		}

		all = false
	},
}

Cmd is the ls command's entrypoint

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL