1package main 2 3import ( 4 "fmt" 5 "os" 6 "text/tabwriter" 7 8 "github.com/Microsoft/hcsshim/internal/appargs" 9 "github.com/urfave/cli" 10) 11 12var listCommand = cli.Command{ 13 Name: "list", 14 Usage: "Lists running shims", 15 ArgsUsage: " ", 16 Flags: []cli.Flag{ 17 cli.BoolFlag{ 18 Name: "pids", 19 Usage: "Shows the process IDs of each shim", 20 }, 21 }, 22 Before: appargs.Validate(), 23 Action: func(ctx *cli.Context) error { 24 pids := ctx.Bool("pids") 25 shims, err := findShims("") 26 if err != nil { 27 return err 28 } 29 30 w := new(tabwriter.Writer) 31 w.Init(os.Stdout, 0, 8, 0, '\t', 0) 32 33 if pids { 34 fmt.Fprintln(w, "Shim \t Pid") 35 } 36 37 for _, shim := range shims { 38 if pids { 39 pid, err := getPid(shim) 40 if err != nil { 41 return err 42 } 43 fmt.Fprintf(w, "%s \t %d\n", shim, pid) 44 } else { 45 fmt.Fprintln(w, shim) 46 } 47 } 48 w.Flush() 49 return nil 50 }, 51} 52