github.com/kolanos/fargate@v0.2.3/cmd/task_list.go (about)

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"text/tabwriter"
     7  
     8  	"github.com/jpignata/fargate/console"
     9  	ECS "github.com/jpignata/fargate/ecs"
    10  	"github.com/spf13/cobra"
    11  )
    12  
    13  var taskListCmd = &cobra.Command{
    14  	Use:   "list",
    15  	Short: "List running task groups",
    16  	Run: func(cmd *cobra.Command, args []string) {
    17  		listTaskGroups()
    18  	},
    19  }
    20  
    21  func init() {
    22  	taskCmd.AddCommand(taskListCmd)
    23  }
    24  
    25  func listTaskGroups() {
    26  	ecs := ECS.New(sess, clusterName)
    27  	taskGroups := ecs.ListTaskGroups()
    28  
    29  	if len(taskGroups) == 0 {
    30  		console.InfoExit("No tasks running")
    31  	}
    32  
    33  	w := new(tabwriter.Writer)
    34  	w.Init(os.Stdout, 0, 8, 1, '\t', 0)
    35  	fmt.Fprintln(w, "NAME\tINSTANCES")
    36  
    37  	for _, taskGroup := range taskGroups {
    38  		fmt.Fprintf(w, "%s\t%d\n",
    39  			taskGroup.TaskGroupName,
    40  			taskGroup.Instances,
    41  		)
    42  	}
    43  
    44  	w.Flush()
    45  }