MCPcopy
hub / github.com/perkeep/perkeep / RunCommand

Method RunCommand

cmd/pk/list.go:73–153  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

71}
72
73func (c *listCmd) RunCommand(args []string) error {
74 c.describe = c.describe || c.camliType != ""
75
76 if !c.describe {
77 return c.syncCmd.RunCommand(args)
78 }
79
80 stdout := cmdmain.Stdout
81 defer func() { cmdmain.Stdout = stdout }()
82 pr, pw, err := os.Pipe()
83 if err != nil {
84 return fmt.Errorf("Could not create pipe to read from stdout: %v", err)
85 }
86 defer pr.Close()
87 cmdmain.Stdout = pw
88
89 if err := c.setClient(); err != nil {
90 return err
91 }
92
93 scanner := bufio.NewScanner(pr)
94 go func() {
95 err := c.syncCmd.RunCommand(args)
96 if err != nil {
97 log.Printf("Error when enumerating source with sync: %v", err)
98 }
99 pw.Close()
100 }()
101
102 blobRefs := make([]blob.Ref, 0, describeBatchSize)
103 describe := func() error {
104 if len(blobRefs) == 0 {
105 return nil
106 }
107 // TODO(mpl): setting depth to 1, not 0, because otherwise r.depth() in pkg/search/handler.go defaults to 4. Can't remember why we disallowed 0 right now, and I do not want to change that in pkg/search/handler.go and risk breaking things.
108 described, err := c.cl.Describe(context.Background(), &search.DescribeRequest{
109 BlobRefs: blobRefs,
110 Depth: 1,
111 })
112 if err != nil {
113 return fmt.Errorf("Error when describing blobs %v: %v", blobRefs, err)
114 }
115 for _, v := range blobRefs {
116 blob, ok := described.Meta[v.String()]
117 if !ok {
118 // This can happen if the index is out of sync with the storage we enum from.
119 fmt.Fprintf(stdout, "%v <not described>\n", v)
120 continue
121 }
122
123 if c.camliType == "" || string(blob.CamliType) == c.camliType {
124 detailed := detail(blob)
125 if detailed != "" {
126 detailed = fmt.Sprintf("\t%v", detailed)
127 }
128 fmt.Fprintf(stdout, "%v %v%v\n", v, blob.Size, detailed)
129 }
130 }

Callers

nothing calls this directly

Calls 10

setClientMethod · 0.95
MustParseFunction · 0.92
detailFunction · 0.85
PrintfMethod · 0.80
RunCommandMethod · 0.65
CloseMethod · 0.65
DescribeMethod · 0.65
TextMethod · 0.65
StringMethod · 0.45
ErrMethod · 0.45

Tested by

no test coverage detected