|
5 | 5 | "encoding/json" |
6 | 6 | "fmt" |
7 | 7 | "strconv" |
| 8 | + "strings" |
8 | 9 |
|
9 | 10 | "github.com/github/git-sizer/counts" |
10 | 11 | "github.com/github/git-sizer/git" |
@@ -218,6 +219,26 @@ func (i *item) MarshalJSON() ([]byte, error) { |
218 | 219 | return json.Marshal(stat) |
219 | 220 | } |
220 | 221 |
|
| 222 | +// Indented returns an `item` that is just like `i`, but indented by |
| 223 | +// `depth` more levels. |
| 224 | +func (i *item) Indented(depth int) tableContents { |
| 225 | + return &indentedItem{ |
| 226 | + tableContents: i, |
| 227 | + depth: depth, |
| 228 | + } |
| 229 | +} |
| 230 | + |
| 231 | +type indentedItem struct { |
| 232 | + tableContents |
| 233 | + depth int |
| 234 | +} |
| 235 | + |
| 236 | +func (i *indentedItem) Emit(t *table) { |
| 237 | + subTable := t.indented("", i.depth) |
| 238 | + i.tableContents.Emit(subTable) |
| 239 | + t.addSection(subTable) |
| 240 | +} |
| 241 | + |
221 | 242 | type Threshold float64 |
222 | 243 |
|
223 | 244 | // Methods to implement pflag.Value: |
@@ -365,16 +386,20 @@ func (s HistorySize) TableString( |
365 | 386 | return t.generateHeader() + t.buf.String() + t.footnotes.String() |
366 | 387 | } |
367 | 388 |
|
368 | | -func (t *table) subTable(sectionHeader string) *table { |
| 389 | +func (t *table) indented(sectionHeader string, depth int) *table { |
369 | 390 | return &table{ |
370 | 391 | threshold: t.threshold, |
371 | 392 | nameStyle: t.nameStyle, |
372 | 393 | sectionHeader: sectionHeader, |
373 | 394 | footnotes: t.footnotes, |
374 | | - indent: t.indent + 1, |
| 395 | + indent: t.indent + depth, |
375 | 396 | } |
376 | 397 | } |
377 | 398 |
|
| 399 | +func (t *table) subTable(sectionHeader string) *table { |
| 400 | + return t.indented(sectionHeader, 1) |
| 401 | +} |
| 402 | + |
378 | 403 | func (t *table) addSection(subTable *table) { |
379 | 404 | if subTable.buf.Len() > 0 { |
380 | 405 | if t.buf.Len() == 0 { |
@@ -449,14 +474,13 @@ func (s HistorySize) contents(refGroups []RefGroup) tableContents { |
449 | 474 | if !ok { |
450 | 475 | continue |
451 | 476 | } |
452 | | - rgis = append( |
453 | | - rgis, |
454 | | - I( |
455 | | - fmt.Sprintf("refgroup.%s", rg.Symbol), rg.Name, |
456 | | - fmt.Sprintf("The number of references in group '%s'", rg.Symbol), |
457 | | - nil, *count, metric, "", 25000, |
458 | | - ), |
| 477 | + rgi := I( |
| 478 | + fmt.Sprintf("refgroup.%s", rg.Symbol), rg.Name, |
| 479 | + fmt.Sprintf("The number of references in group '%s'", rg.Symbol), |
| 480 | + nil, *count, metric, "", 25000, |
459 | 481 | ) |
| 482 | + indent := strings.Count(string(rg.Symbol), ".") |
| 483 | + rgis = append(rgis, rgi.Indented(indent)) |
460 | 484 | } |
461 | 485 |
|
462 | 486 | return S( |
|
0 commit comments