2020-06-12 10:53:06 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
"github.com/docker/api/client"
|
|
|
|
)
|
|
|
|
|
2020-06-15 10:38:37 +02:00
|
|
|
// InspectCommand inspects into containers
|
2020-06-12 10:53:06 +02:00
|
|
|
func InspectCommand() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "inspect",
|
|
|
|
Short: "Inspect containers",
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return runInspect(cmd.Context(), args[0])
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func runInspect(ctx context.Context, id string) error {
|
|
|
|
c, err := client.New(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "cannot connect to backend")
|
|
|
|
}
|
|
|
|
|
|
|
|
container, err := c.ContainerService().Inspect(ctx, id)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
b, err := json.MarshalIndent(container, "", " ")
|
|
|
|
containerString := string(b)
|
|
|
|
fmt.Println(containerString)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|