MCPcopy
hub / github.com/redspread/spread / Show

Method Show

cli/show.go:13–57  ·  view source on GitHub ↗

Show displays data stored in Spread Documents.

()

Source from the content-addressed store, hash-verified

11
12// Show displays data stored in Spread Documents.
13func (s SpreadCli) Show() *cli.Command {
14 return &cli.Command{
15 Name: "show",
16 Usage: "Display information stored in a repository",
17 ArgsUsage: "<revision> <path>",
18 Action: func(c *cli.Context) {
19 var doc *pb.Document
20 p := s.projectOrDie()
21 switch len(c.Args()) {
22 case 1: // from index
23 docs, err := p.Index()
24 if err != nil {
25 s.fatalf("Failed to get index: %v", err)
26 }
27 path := c.Args().First()
28 var ok bool
29 if doc, ok = docs[path]; !ok {
30 s.fatalf("Path '%s' not found in index.", path)
31 }
32 case 2: // from revision
33 revision := c.Args().First()
34 path := c.Args().Get(1)
35 var err error
36 doc, err = p.GetDocument(revision, path)
37 if err != nil {
38 s.fatalf("failed to get document: %v", err)
39 }
40 default:
41 s.fatalf("a path OR path and revision must be specified")
42 }
43
44 fields, err := data.MapFromDocument(doc)
45 if err != nil {
46 s.fatalf("could not get fields: %v", err)
47 }
48
49 out, err := json.MarshalIndent(&fields, "", "\t")
50 if err != nil {
51 s.fatalf("Couldn't create JSON: %v", err)
52 }
53
54 s.printf("%s", out)
55 },
56 }
57}

Callers

nothing calls this directly

Calls 6

projectOrDieMethod · 0.95
fatalfMethod · 0.95
printfMethod · 0.95
IndexMethod · 0.80
GetDocumentMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected