File: dump.go

package info (click to toggle)
continuity 0.0~git20180216.d8fb858-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 620 kB
  • sloc: makefile: 46; sh: 28; asm: 3
file content (44 lines) | stat: -rw-r--r-- 980 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package commands

import (
	"io/ioutil"
	"log"
	"os"

	pb "github.com/containerd/continuity/proto"
	"github.com/golang/protobuf/proto"
	"github.com/spf13/cobra"
)

var DumpCmd = &cobra.Command{
	Use:   "dump <manifest>",
	Short: "Dump the contents of the manifest in protobuf text format",
	Run: func(cmd *cobra.Command, args []string) {
		var p []byte
		var err error

		if len(args) < 1 {
			p, err = ioutil.ReadAll(os.Stdin)
			if err != nil {
				log.Fatalf("error reading manifest: %v", err)
			}
		} else {
			p, err = ioutil.ReadFile(args[0])
			if err != nil {
				log.Fatalf("error reading manifest: %v", err)
			}
		}

		var bm pb.Manifest

		if err := proto.Unmarshal(p, &bm); err != nil {
			log.Fatalf("error unmarshaling manifest: %v", err)
		}

		// TODO(stevvooe): For now, just dump the text format. Turn this into
		// nice text output later.
		if err := proto.MarshalText(os.Stdout, &bm); err != nil {
			log.Fatalf("error dumping manifest: %v", err)
		}
	},
}