2014-06-05 07:46:30 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/codegangsta/cli"
|
2014-06-10 23:14:16 +08:00
|
|
|
"github.com/docker/libcontainer"
|
2014-06-05 07:46:30 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var specCommand = cli.Command{
|
|
|
|
Name: "spec",
|
|
|
|
Usage: "display the container specification",
|
|
|
|
Action: specAction,
|
|
|
|
}
|
|
|
|
|
|
|
|
func specAction(context *cli.Context) {
|
2014-06-06 05:28:09 +08:00
|
|
|
container, err := loadContainer()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-06-05 07:46:30 +08:00
|
|
|
spec, err := getContainerSpec(container)
|
|
|
|
if err != nil {
|
2014-06-06 05:28:09 +08:00
|
|
|
log.Fatalf("Failed to get spec - %v\n", err)
|
2014-06-05 07:46:30 +08:00
|
|
|
}
|
|
|
|
|
2014-06-06 05:28:09 +08:00
|
|
|
fmt.Printf("Spec:\n%v\n", spec)
|
2014-06-05 07:46:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// returns the container spec in json format.
|
|
|
|
func getContainerSpec(container *libcontainer.Container) (string, error) {
|
|
|
|
spec, err := json.MarshalIndent(container, "", "\t")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2014-06-06 05:28:09 +08:00
|
|
|
|
2014-06-05 07:46:30 +08:00
|
|
|
return string(spec), nil
|
|
|
|
}
|