Files
kopia/cli/command_show.go
Jarek Kowalski fcd507a56d Refactored most of the CLI tests to run in-process as opposed to using sub-processes (#1059)
* cli: fixed remaining testability indirections for output and logging

* cli: added cli.RunSubcommand() which is used in testing to execute a subcommand in the same process

* tests: refactored most e2e tests to invoke kopia subcommands in-process

* Makefile: enable code coverage for cli/ and internal/

* testing: pass 'testing' tag to unit tests which uses much faster (insecure) password hashing scheme

* Makefile: push coverage from PRs again

* tests: disable buffer management to reduce memory usage on ARM

* cli: fixed misaligned atomic field on ARMHF

also temporarily fixed statup-time benign race condition when setting
default on the timeZone variable, which is the last global variable.
2021-05-11 22:26:28 -07:00

44 lines
996 B
Go

package cli
import (
"context"
"github.com/pkg/errors"
"github.com/kopia/kopia/internal/iocopy"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/snapshot/snapshotfs"
)
type commandShow struct {
path string
out textOutput
}
func (c *commandShow) setup(svc appServices, parent commandParent) {
cmd := parent.Command("show", "Displays contents of a repository object.").Alias("cat")
cmd.Arg("object-path", "Path").Required().StringVar(&c.path)
cmd.Action(svc.repositoryReaderAction(c.run))
c.out.setup(svc)
}
func (c *commandShow) run(ctx context.Context, rep repo.Repository) error {
oid, err := snapshotfs.ParseObjectIDWithPath(ctx, rep, c.path)
if err != nil {
return errors.Wrapf(err, "unable to parse ID: %v", c.path)
}
r, err := rep.OpenObject(ctx, oid)
if err != nil {
return errors.Wrapf(err, "error opening object %v", oid)
}
defer r.Close() //nolint:errcheck
_, err = iocopy.Copy(c.out.stdout(), r)
return errors.Wrap(err, "unable to copy data")
}