-
Notifications
You must be signed in to change notification settings - Fork 0
/
raw.go
49 lines (42 loc) · 816 Bytes
/
raw.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
package toto
import (
"fmt"
"github.com/spf13/cobra"
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/emptypb"
"io"
"os"
)
func newRawCommand(t *options) *cobra.Command {
cmd := &cobra.Command{
Use: "raw",
Args: cobra.NoArgs,
RunE: func(_ *cobra.Command, _ []string) error {
return runRaw()
},
}
return cmd
}
func runRaw() error {
bs, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
m := emptypb.Empty{}
if err := proto.Unmarshal(bs, &m); err != nil {
return err
}
opts := prototext.MarshalOptions{
Multiline: true,
AllowPartial: true,
EmitUnknown: true,
Indent: " ",
}
out, err := opts.Marshal(&m)
if err != nil {
return err
}
fmt.Println(string(out))
return nil
}