spec.go 739 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "log"
  6. "github.com/codegangsta/cli"
  7. "github.com/docker/libcontainer"
  8. )
  9. var specCommand = cli.Command{
  10. Name: "spec",
  11. Usage: "display the container specification",
  12. Action: specAction,
  13. }
  14. func specAction(context *cli.Context) {
  15. container, err := loadContainer()
  16. if err != nil {
  17. log.Fatal(err)
  18. }
  19. spec, err := getContainerSpec(container)
  20. if err != nil {
  21. log.Fatalf("Failed to get spec - %v\n", err)
  22. }
  23. fmt.Printf("Spec:\n%v\n", spec)
  24. }
  25. // returns the container spec in json format.
  26. func getContainerSpec(container *libcontainer.Config) (string, error) {
  27. spec, err := json.MarshalIndent(container, "", "\t")
  28. if err != nil {
  29. return "", err
  30. }
  31. return string(spec), nil
  32. }