ls

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2024 License: Apache-2.0 Imports: 15 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. If the -c arg is supplied, operates on changesets instead of stacks

Usage:
  ls <stack> [changeset]

Aliases:
  ls, list

Flags:
  -a, --all         list stacks in all regions; if you specify a stack, show more details
  -c, --changeset   List changesets instead of stacks
  -h, --help        help for ls

Index

Examples

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:                   "ls <stack> [changeset]",
	Short:                 "List running CloudFormation stacks or changesets",
	Long:                  "Displays a list of all running stacks or the contents of <stack> if provided. If the -c arg is supplied, operates on changesets instead of stacks",
	Args:                  cobra.MaximumNArgs(2),
	Aliases:               []string{"list"},
	DisableFlagsInUseLine: true,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) > 0 {

			if changeset {

				if len(args) != 2 {
					panic("Usage: rain ls -c stackName changeSetName")
				}

				stackName := args[0]
				changeSetName := args[1]
				showChangeset(stackName, changeSetName)

				return
			}

			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)
			fmt.Println(console.Yellow("  ChangeSets:"))
			err = ShowChangeSetsForStack(*stack.StackName)
			if err != nil {
				panic(err)
			}
		} 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)

				if changeset {
					fmt.Println(console.Yellow(fmt.Sprintf("Stacks with changesets in %s:", region)))
					for _, stack := range stacks {
						if stack.StackName == nil {
							continue
						}
						config.Debugf("Checking stack %s", *stack.StackName)

						err := ShowChangeSetsForStack(*stack.StackName)
						if err != nil {
							panic(err)
						}

					}

				} else {

					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

func ShowChangeSetsForStack added in v1.8.0

func ShowChangeSetsForStack(stackName string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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