printPage prints given page to cmd.Stdout and returns error or number of interpreted pages.
(cmd *cobra.Command, path string, pageID uint64, formatValue string)
| 78 | |
| 79 | // printPage prints given page to cmd.Stdout and returns error or number of interpreted pages. |
| 80 | func printPage(cmd *cobra.Command, path string, pageID uint64, formatValue string) (numPages uint32, reterr error) { |
| 81 | defer func() { |
| 82 | if err := recover(); err != nil { |
| 83 | reterr = fmt.Errorf("%s", err) |
| 84 | } |
| 85 | }() |
| 86 | |
| 87 | // retrieve page info and page size. |
| 88 | p, buf, err := guts_cli.ReadPage(path, pageID) |
| 89 | if err != nil { |
| 90 | return 0, err |
| 91 | } |
| 92 | |
| 93 | // print basic page info. |
| 94 | stdout := cmd.OutOrStdout() |
| 95 | fmt.Fprintf(stdout, "Page ID: %d\n", p.Id()) |
| 96 | fmt.Fprintf(stdout, "Page Type: %s\n", p.Typ()) |
| 97 | fmt.Fprintf(stdout, "Total Size: %d bytes\n", len(buf)) |
| 98 | fmt.Fprintf(stdout, "Overflow pages: %d\n", p.Overflow()) |
| 99 | |
| 100 | // print type-specific data. |
| 101 | switch p.Typ() { |
| 102 | case "meta": |
| 103 | err = pagePrintMeta(stdout, buf) |
| 104 | case "leaf": |
| 105 | err = pagePrintLeaf(stdout, buf, formatValue) |
| 106 | case "branch": |
| 107 | err = pagePrintBranch(stdout, buf) |
| 108 | case "freelist": |
| 109 | err = pagePrintFreelist(stdout, buf) |
| 110 | } |
| 111 | if err != nil { |
| 112 | return 0, err |
| 113 | } |
| 114 | return p.Overflow(), nil |
| 115 | } |
| 116 | |
| 117 | func printAllPages(cmd *cobra.Command, path string, formatValue string) { |
| 118 | _, hwm, err := guts_cli.ReadPageAndHWMSize(path) |
no test coverage detected