Show displays data stored in Spread Documents.
()
| 11 | |
| 12 | // Show displays data stored in Spread Documents. |
| 13 | func (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 | } |
nothing calls this directly
no test coverage detected