Files
kopia/cli/command_show.go
Jarek Kowalski 0758a92c58 restore: improved user experience (#644)
* restore: improved user experience

* 'snapshot restore' is now the same as 'restore' and both will
  support restoring by manifest ID, root ID or root ID + subdirectory

* added support for restoring individual files

* implemented PR feedback and refactored object ID parsing

Moving helpers inside the snapshot/ package helped clean up the code
a lot.
2020-09-28 22:57:24 -07:00

38 lines
745 B
Go

package cli
import (
"context"
"os"
"github.com/kopia/kopia/internal/iocopy"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/snapshot/snapshotfs"
)
var (
catCommand = app.Command("show", "Displays contents of a repository object.").Alias("cat")
catCommandPath = catCommand.Arg("object-path", "Path").Required().String()
)
func runCatCommand(ctx context.Context, rep repo.Repository) error {
oid, err := snapshotfs.ParseObjectIDWithPath(ctx, rep, *catCommandPath)
if err != nil {
return err
}
r, err := rep.OpenObject(ctx, oid)
if err != nil {
return err
}
defer r.Close() //nolint:errcheck
_, err = iocopy.Copy(os.Stdout, r)
return err
}
func init() {
catCommand.Action(repositoryAction(runCatCommand))
}