ls

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2020 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 or 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"},
	Annotations:           cmd.StackAnnotation,
	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 := ui.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