Skip to content

Commit 1737fca

Browse files
authored
make gitea admin auth list formatting configurable (#10844)
* make admin auth list formatting configurable Signed-off-by: Andrew Thornton <[email protected]> * As per @guillep2k Signed-off-by: Andrew Thornton <[email protected]>
1 parent 8cffae6 commit 1737fca

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

cmd/admin.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,32 @@ var (
146146
Name: "list",
147147
Usage: "List auth sources",
148148
Action: runListAuth,
149+
Flags: []cli.Flag{
150+
cli.IntFlag{
151+
Name: "min-width",
152+
Usage: "Minimal cell width including any padding for the formatted table",
153+
Value: 0,
154+
},
155+
cli.IntFlag{
156+
Name: "tab-width",
157+
Usage: "width of tab characters in formatted table (equivalent number of spaces)",
158+
Value: 8,
159+
},
160+
cli.IntFlag{
161+
Name: "padding",
162+
Usage: "padding added to a cell before computing its width",
163+
Value: 1,
164+
},
165+
cli.StringFlag{
166+
Name: "pad-char",
167+
Usage: `ASCII char used for padding if padchar == '\\t', the Writer will assume that the width of a '\\t' in the formatted output is tabwidth, and cells are left-aligned independent of align_left (for correct-looking results, tabwidth must correspond to the tab width in the viewer displaying the result)`,
168+
Value: "\t",
169+
},
170+
cli.BoolFlag{
171+
Name: "vertical-bars",
172+
Usage: "Set to true to print vertical bars between columns",
173+
},
174+
},
149175
}
150176

151177
idFlag = cli.Int64Flag{
@@ -535,8 +561,18 @@ func runListAuth(c *cli.Context) error {
535561
return err
536562
}
537563

564+
flags := tabwriter.AlignRight
565+
if c.Bool("vertical-bars") {
566+
flags |= tabwriter.Debug
567+
}
568+
569+
padChar := byte('\t')
570+
if len(c.String("pad-char")) > 0 {
571+
padChar = c.String("pad-char")[0]
572+
}
573+
538574
// loop through each source and print
539-
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.AlignRight)
575+
w := tabwriter.NewWriter(os.Stdout, c.Int("min-width"), c.Int("tab-width"), c.Int("padding"), padChar, flags)
540576
fmt.Fprintf(w, "ID\tName\tType\tEnabled\n")
541577
for _, source := range loginSources {
542578
fmt.Fprintf(w, "%d\t%s\t%s\t%t\n", source.ID, source.Name, models.LoginNames[source.Type], source.IsActived)

0 commit comments

Comments
 (0)