-
Notifications
You must be signed in to change notification settings - Fork 332
/
fs_cat.go
52 lines (46 loc) · 1.09 KB
/
fs_cat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package cmd
import (
"io"
"net/http"
"os"
"github.com/go-openapi/swag"
"github.com/spf13/cobra"
"github.com/treeverse/lakefs/pkg/api/apigen"
)
var fsCatCmd = &cobra.Command{
Use: "cat <path URI>",
Short: "Dump content of object to stdout",
Args: cobra.ExactArgs(1),
ValidArgsFunction: ValidArgsRepository,
Run: func(cmd *cobra.Command, args []string) {
pathURI := MustParsePathURI("path URI", args[0])
client := getClient()
preSignMode := getPresignMode(cmd, client)
var err error
var body io.ReadCloser
var resp *http.Response
resp, err = client.GetObject(cmd.Context(), pathURI.Repository, pathURI.Ref, &apigen.GetObjectParams{
Path: *pathURI.Path,
Presign: swag.Bool(preSignMode.Enabled),
})
DieOnHTTPError(resp)
body = resp.Body
if err != nil {
DieErr(err)
}
defer func() {
if err := body.Close(); err != nil {
DieErr(err)
}
}()
_, err = io.Copy(os.Stdout, body)
if err != nil {
DieErr(err)
}
},
}
//nolint:gochecknoinits
func init() {
withPresignFlag(fsCatCmd)
fsCmd.AddCommand(fsCatCmd)
}