mirror of
https://github.com/kopia/kopia.git
synced 2026-01-25 14:58:00 -05:00
51 lines
1000 B
Go
51 lines
1000 B
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
"github.com/kopia/kopia/object"
|
|
"github.com/kopia/kopia/repo"
|
|
"github.com/kopia/kopia/snapshot"
|
|
)
|
|
|
|
var (
|
|
showCommand = objectCommands.Command("show", "Show contents of a repository object.").Alias("cat")
|
|
|
|
showObjectIDs = showCommand.Arg("id", "IDs of objects to show").Required().Strings()
|
|
)
|
|
|
|
func runShowCommand(ctx context.Context, rep *repo.Repository) error {
|
|
mgr := snapshot.NewManager(rep)
|
|
|
|
for _, oidString := range *showObjectIDs {
|
|
oid, err := parseObjectID(ctx, mgr, oidString)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := showObject(ctx, rep, oid); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func showObject(ctx context.Context, r *repo.Repository, oid object.ID) error {
|
|
var rd io.ReadCloser
|
|
|
|
rd, err := r.Objects.Open(ctx, oid)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer rd.Close() //nolint:errcheck
|
|
|
|
return showContent(rd)
|
|
}
|
|
|
|
func init() {
|
|
setupShowCommand(showCommand)
|
|
showCommand.Action(repositoryAction(runShowCommand))
|
|
}
|