Files
kopia/cli/command_content_show.go
Jarek Kowalski e03971fc59 Upgraded linter to v1.33.0 (#734)
* linter: upgraded to 1.33, disabled some linters

* lint: fixed 'errorlint' errors

This ensures that all error comparisons use errors.Is() or errors.As().
We will be wrapping more errors going forward so it's important that
error checks are not strict everywhere.

Verified that there are no exceptions for errorlint linter which
guarantees that.

* lint: fixed or suppressed wrapcheck errors

* lint: nolintlint and misc cleanups

Co-authored-by: Julio López <julio+gh@kasten.io>
2020-12-21 22:39:22 -08:00

42 lines
983 B
Go

package cli
import (
"bytes"
"context"
"github.com/pkg/errors"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/repo/content"
)
var (
contentShowCommand = contentCommands.Command("show", "Show contents by ID.").Alias("cat")
contentShowIDs = contentShowCommand.Arg("id", "IDs of contents to show").Required().Strings()
)
func runContentShowCommand(ctx context.Context, rep *repo.DirectRepository) error {
for _, contentID := range toContentIDs(*contentShowIDs) {
if err := contentShow(ctx, rep, contentID); err != nil {
return err
}
}
return nil
}
func contentShow(ctx context.Context, r *repo.DirectRepository, contentID content.ID) error {
data, err := r.Content.GetContent(ctx, contentID)
if err != nil {
return errors.Wrapf(err, "error getting content %v", contentID)
}
return showContent(bytes.NewReader(data))
}
func init() {
setupShowCommand(contentShowCommand)
contentShowCommand.Action(directRepositoryAction(runContentShowCommand))
}