43 lines
940 B
Go
43 lines
940 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/containers/storage/pkg/mflag"
|
|
"github.com/containers/storage/storage"
|
|
)
|
|
|
|
func containers(flags *mflag.FlagSet, action string, m storage.Mall, args []string) int {
|
|
containers, err := m.Containers()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "%v\n", err)
|
|
return 1
|
|
}
|
|
if jsonOutput {
|
|
json.NewEncoder(os.Stdout).Encode(containers)
|
|
} else {
|
|
for _, container := range containers {
|
|
fmt.Printf("%s\n", container.ID)
|
|
if container.Name != "" {
|
|
fmt.Printf("\t%s\n", container.Name)
|
|
}
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func init() {
|
|
commands = append(commands, command{
|
|
names: []string{"containers"},
|
|
optionsHelp: "[options [...]]",
|
|
usage: "List containers",
|
|
action: containers,
|
|
maxArgs: 0,
|
|
addFlags: func(flags *mflag.FlagSet, cmd *command) {
|
|
flags.BoolVar(&jsonOutput, []string{"-json", "j"}, jsonOutput, "prefer JSON output")
|
|
},
|
|
})
|
|
}
|