Skip to content

Commit cbf0d20

Browse files
authored
Merge pull request #20 from SwissLife-OSS/compact-format
Add compact format
2 parents 37a1782 + e09b848 commit cbf0d20

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

cmd_ilm_list.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"github.com/elastic/go-elasticsearch/v8/typedapi/types"
1717
"github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/bytes"
1818
"github.com/olekukonko/tablewriter"
19+
"github.com/olekukonko/tablewriter/renderer"
20+
"github.com/olekukonko/tablewriter/tw"
1921
"github.com/urfave/cli/v3"
2022
)
2123

@@ -30,6 +32,7 @@ func ilmList(ctx context.Context, cmd *cli.Command) error {
3032
minPriSizeStr := cmd.String("min-pri-size")
3133
minTotalSizeStr := cmd.String("min-total-size")
3234
minAge := time.Duration(cmd.Int("min-age-days")) * 24 * time.Hour
35+
format := cmd.String("format")
3336

3437
if !isRegionValid(region) {
3538
return fmt.Errorf("region %q is not a known Elastic Cloud region", region)
@@ -218,7 +221,29 @@ func ilmList(ctx context.Context, cmd *cli.Command) error {
218221
data = append(data, []string{item.name, item.phase, item.action, item.step, item.policy, formatDuration(item.age), units.BytesSize(float64(item.priSize)), units.BytesSize(float64(item.totalSize))})
219222
}
220223

221-
table := tablewriter.NewWriter(os.Stdout)
224+
opts := []tablewriter.Option{
225+
tablewriter.WithRenderer(
226+
renderer.NewBlueprint(),
227+
),
228+
}
229+
switch format {
230+
case "compact":
231+
opts = []tablewriter.Option{
232+
tablewriter.WithRenderer(
233+
renderer.NewBlueprint(
234+
tw.Rendition{
235+
Borders: tw.BorderNone,
236+
Settings: tw.Settings{
237+
Lines: tw.LinesNone,
238+
Separators: tw.SeparatorsNone,
239+
},
240+
},
241+
),
242+
),
243+
}
244+
}
245+
246+
table := tablewriter.NewTable(os.Stdout, opts...)
222247
table.Header([]string{
223248
"Index", "Phase", "Action", "Step", "Policy", "Age", "Pri Size", "Total Size",
224249
})

main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ func run(ctx context.Context, args []string) error {
8585
Name: "min-age-days",
8686
Usage: "Minimum age of index in days in order to be contained in the result",
8787
},
88+
&cli.StringFlag{
89+
Name: "format",
90+
Aliases: []string{"f"},
91+
Usage: "Format for the result: table, compact (default: table)",
92+
},
8893
},
8994
Action: ilmList,
9095
},

0 commit comments

Comments
 (0)