summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-03-27 21:26:43 +0000
committerGitHub <noreply@github.com>2020-03-27 22:26:43 +0100
commit1737fca220c8fe3bf2d66076efe05d28cdb6d06e (patch)
treebf65d437615a163310681dc6dcfa49bf0100ec8a /cmd
parent8cffae65a60326a26d118af815346e830e9dda78 (diff)
downloadgitea-1737fca220c8fe3bf2d66076efe05d28cdb6d06e.tar.gz
gitea-1737fca220c8fe3bf2d66076efe05d28cdb6d06e.zip
make `gitea admin auth list` formatting configurable (#10844)
* make admin auth list formatting configurable Signed-off-by: Andrew Thornton <art27@cantab.net> * As per @guillep2k Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/admin.go38
1 files changed, 37 insertions, 1 deletions
diff --git a/cmd/admin.go b/cmd/admin.go
index bc469cdae3..a049f7f2cf 100644
--- a/cmd/admin.go
+++ b/cmd/admin.go
@@ -146,6 +146,32 @@ var (
Name: "list",
Usage: "List auth sources",
Action: runListAuth,
+ Flags: []cli.Flag{
+ cli.IntFlag{
+ Name: "min-width",
+ Usage: "Minimal cell width including any padding for the formatted table",
+ Value: 0,
+ },
+ cli.IntFlag{
+ Name: "tab-width",
+ Usage: "width of tab characters in formatted table (equivalent number of spaces)",
+ Value: 8,
+ },
+ cli.IntFlag{
+ Name: "padding",
+ Usage: "padding added to a cell before computing its width",
+ Value: 1,
+ },
+ cli.StringFlag{
+ Name: "pad-char",
+ 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)`,
+ Value: "\t",
+ },
+ cli.BoolFlag{
+ Name: "vertical-bars",
+ Usage: "Set to true to print vertical bars between columns",
+ },
+ },
}
idFlag = cli.Int64Flag{
@@ -535,8 +561,18 @@ func runListAuth(c *cli.Context) error {
return err
}
+ flags := tabwriter.AlignRight
+ if c.Bool("vertical-bars") {
+ flags |= tabwriter.Debug
+ }
+
+ padChar := byte('\t')
+ if len(c.String("pad-char")) > 0 {
+ padChar = c.String("pad-char")[0]
+ }
+
// loop through each source and print
- w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.AlignRight)
+ w := tabwriter.NewWriter(os.Stdout, c.Int("min-width"), c.Int("tab-width"), c.Int("padding"), padChar, flags)
fmt.Fprintf(w, "ID\tName\tType\tEnabled\n")
for _, source := range loginSources {
fmt.Fprintf(w, "%d\t%s\t%s\t%t\n", source.ID, source.Name, models.LoginNames[source.Type], source.IsActived)