mirror of
https://github.com/kopia/kopia.git
synced 2026-01-25 14:58:00 -05:00
38 lines
656 B
Go
38 lines
656 B
Go
package cli
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/kopia/kopia/snapshot"
|
|
|
|
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
|
)
|
|
|
|
var (
|
|
catCommand = app.Command("cat", "Displays contents of a repository object.")
|
|
catCommandPath = catCommand.Arg("path", "Path").Required().String()
|
|
)
|
|
|
|
func runCatCommand(context *kingpin.ParseContext) error {
|
|
rep := mustOpenRepository(nil)
|
|
defer rep.Close()
|
|
|
|
mgr := snapshot.NewManager(rep)
|
|
|
|
oid, err := parseObjectID(mgr, *catCommandPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
r, err := rep.Objects.Open(oid)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
io.Copy(os.Stdout, r)
|
|
return nil
|
|
}
|
|
|
|
func init() {
|
|
catCommand.Action(runCatCommand)
|
|
}
|