commands

package
v0.0.0-...-83fe70d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2015 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ApplyCmd = &cobra.Command{
	Use:   "apply <manifest> <root>",
	Short: "Apply the manifest to the provided root",
	Run: func(cmd *cobra.Command, args []string) {

	},
}
View Source
var (
	BuildCmd = &cobra.Command{
		Use:   "build <root>",
		Short: "Build a manifest for the provided root",
		Run: func(cmd *cobra.Command, args []string) {
			if len(args) != 1 {
				log.Fatalln("please specify a root")
			}

			ctx, err := continuity.NewContext(args[0])
			if err != nil {
				log.Fatalf("error creating path context: %v", err)
			}

			m, err := continuity.BuildManifest(ctx)
			if err != nil {
				log.Fatalf("error generating manifest: %v", err)
			}

			p, err := proto.Marshal(m)
			if err != nil {
				log.Fatalf("error marshing manifest: %v", err)
			}

			os.Stdout.Write(p)
		},
	}
)
View Source
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)
		}

		if err := proto.MarshalText(os.Stdout, &bm); err != nil {
			log.Fatalf("error dumping manifest: %v", err)
		}
	},
}
View Source
var LSCmd = &cobra.Command{
	Use:   "ls <manifest>",
	Short: "List the contents of the manifest.",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 1 {
			log.Fatalln("please specify a manifest")
		}

		bm, err := readManifestFile(args[0])
		if err != nil {
			log.Fatalf("error reading manifest: %v", err)
		}

		w := tabwriter.NewWriter(os.Stdout, 0, 2, 2, ' ', 0)

		for _, entry := range bm.Resource {
			for _, path := range entry.Path {
				fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\n", os.FileMode(entry.Mode), entry.User, entry.Group, humanize.Bytes(uint64(entry.Size)), path)
			}
		}

		w.Flush()
	},
}
View Source
var (
	MainCmd = &cobra.Command{
		Use:   "continuity <command>",
		Short: "A transport-agnostic filesytem metadata tool.",
	}
)
View Source
var (
	StatsCmd = &cobra.Command{
		Use:   "stats <manifest>",
		Short: "display statistics about the specified manifest",
		Run: func(cmd *cobra.Command, args []string) {
			if len(args) != 1 {
				log.Fatalln("please specify a manifest")
			}

			bm, err := readManifestFile(args[0])
			if err != nil {
				log.Fatalf("error reading manifest: %v", err)
			}

			var stats struct {
				resources   int
				files       int
				directories int
				totalSize   int64
				symlinks    int
			}

			for _, entry := range bm.Resource {
				stats.resources++
				stats.totalSize += int64(entry.Size)

				mode := os.FileMode(entry.Mode)
				if mode.IsRegular() {
					stats.files += len(entry.Path)
				} else if mode.IsDir() {
					stats.directories++
				} else if mode&os.ModeSymlink != 0 {
					stats.symlinks++
				}
			}

			w := newTabwriter(os.Stdout)
			defer w.Flush()

			fmt.Fprintf(w, "resources\t%v\n", stats.resources)
			fmt.Fprintf(w, "directories\t%v\n", stats.directories)
			fmt.Fprintf(w, "files\t%v\n", stats.files)
			fmt.Fprintf(w, "symlinks\t%v\n", stats.symlinks)
			fmt.Fprintf(w, "size\t%v\n", humanize.Bytes(uint64(stats.totalSize)))
		},
	}
)
View Source
var VerifyCmd = &cobra.Command{
	Use:   "verify <manifest> <root>",
	Short: "Verify the manifest against the provided root",
	Run: func(cmd *cobra.Command, args []string) {

	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL