From 5cd093aa467ada0017f9056163346f419c0fa546 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Wed, 9 Nov 2016 23:18:22 +0100 Subject: [PATCH 1/2] Use cli Flags directly and not some helper funcs Signed-off-by: Matthias Loibl --- cmd/admin.go | 27 ++++++++++++++++++++++----- cmd/cert.go | 35 +++++++++++++++++++++++++++++------ cmd/cert_stub.go | 2 +- cmd/cmd.go | 42 ------------------------------------------ cmd/dump.go | 23 ++++++++++++++++------- cmd/serve.go | 11 +++++++---- cmd/update.go | 6 +++++- cmd/web.go | 14 +++++++++++--- 8 files changed, 91 insertions(+), 69 deletions(-) delete mode 100644 cmd/cmd.go diff --git a/cmd/admin.go b/cmd/admin.go index de77143f29..5e56f171bf 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -30,11 +30,28 @@ to make automatic initialization process more smoothly`, Usage: "Create a new user in database", Action: runCreateUser, Flags: []cli.Flag{ - stringFlag("name", "", "Username"), - stringFlag("password", "", "User password"), - stringFlag("email", "", "User email address"), - boolFlag("admin", "User is an admin"), - stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"), + cli.StringFlag{ + Name: "name", + Value: "", + Usage: "Username", + }, + cli.StringFlag{ + Name: "password", + Value: "", Usage: "User password", + }, + cli.StringFlag{ + Name: "email", + Value: "", Usage: "User email address", + }, + cli.BoolFlag{ + Name: "admin", + Usage: "User is an admin", + }, + cli.StringFlag{ + Name: "config, c", + Value: "custom/conf/app.ini", + Usage: "Custom configuration file path", + }, }, } ) diff --git a/cmd/cert.go b/cmd/cert.go index 2212d2972d..c30d4ddb70 100644 --- a/cmd/cert.go +++ b/cmd/cert.go @@ -33,12 +33,35 @@ var CmdCert = cli.Command{ Outputs to 'cert.pem' and 'key.pem' and will overwrite existing files.`, Action: runCert, Flags: []cli.Flag{ - stringFlag("host", "", "Comma-separated hostnames and IPs to generate a certificate for"), - stringFlag("ecdsa-curve", "", "ECDSA curve to use to generate a key. Valid values are P224, P256, P384, P521"), - intFlag("rsa-bits", 2048, "Size of RSA key to generate. Ignored if --ecdsa-curve is set"), - stringFlag("start-date", "", "Creation date formatted as Jan 1 15:04:05 2011"), - durationFlag("duration", 365*24*time.Hour, "Duration that certificate is valid for"), - boolFlag("ca", "whether this cert should be its own Certificate Authority"), + cli.StringFlag{ + Name: "host", + Value: "", + Usage: "Comma-separated hostnames and IPs to generate a certificate for", + }, + cli.StringFlag{ + Name: "ecdsa-curve", + Value: "", + Usage: "ECDSA curve to use to generate a key. Valid values are P224, P256, P384, P521", + }, + cli.IntFlag{ + Name: "rsa-bits", + Value: 2048, + Usage: "Size of RSA key to generate. Ignored if --ecdsa-curve is set", + }, + cli.StringFlag{ + Name: "start-date", + Value: "", + Usage: "Creation date formatted as Jan 1 15:04:05 2011", + }, + cli.DurationFlag{ + Name: "duration", + Value: 365 * 24 * time.Hour, + Usage: "Duration that certificate is valid for", + }, + cli.BoolFlag{ + Name: "ca", + Usage: "whether this cert should be its own Certificate Authority", + }, }, } diff --git a/cmd/cert_stub.go b/cmd/cert_stub.go index a97a497e1f..75536f5a7c 100644 --- a/cmd/cert_stub.go +++ b/cmd/cert_stub.go @@ -22,7 +22,7 @@ var CmdCert = cli.Command{ Action: runCert, } -func runCert(ctx *cli.Context) error { +func runCert(*cli.Context) error { fmt.Println("Command cert not available, please use build tags 'cert' to rebuild.") os.Exit(1) diff --git a/cmd/cmd.go b/cmd/cmd.go deleted file mode 100644 index 29afa625d3..0000000000 --- a/cmd/cmd.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package cmd - -import ( - "time" - - "github.com/urfave/cli" -) - -func stringFlag(name, value, usage string) cli.StringFlag { - return cli.StringFlag{ - Name: name, - Value: value, - Usage: usage, - } -} - -func boolFlag(name, usage string) cli.BoolFlag { - return cli.BoolFlag{ - Name: name, - Usage: usage, - } -} - -func intFlag(name string, value int, usage string) cli.IntFlag { - return cli.IntFlag{ - Name: name, - Value: value, - Usage: usage, - } -} - -func durationFlag(name string, value time.Duration, usage string) cli.DurationFlag { - return cli.DurationFlag{ - Name: name, - Value: value, - Usage: usage, - } -} diff --git a/cmd/dump.go b/cmd/dump.go index 8af76e2fc7..60eace35f0 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -6,18 +6,16 @@ package cmd import ( "fmt" + "io/ioutil" "log" "os" "path" "time" - "io/ioutil" - "github.com/Unknwon/cae/zip" - "github.com/urfave/cli" - "github.com/go-gitea/gitea/models" "github.com/go-gitea/gitea/modules/setting" + "github.com/urfave/cli" ) // CmdDump represents the available dump sub-command. @@ -28,9 +26,20 @@ var CmdDump = cli.Command{ It can be used for backup and capture Gogs server image to send to maintainer`, Action: runDump, Flags: []cli.Flag{ - stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"), - boolFlag("verbose, v", "Show process details"), - stringFlag("tempdir, t", os.TempDir(), "Temporary dir path"), + cli.StringFlag{ + Name: "config, c", + Value: "custom/conf/app.ini", + Usage: "Custom configuration file path", + }, + cli.BoolFlag{ + Name: "verbose, v", + Usage: "Show process details", + }, + cli.StringFlag{ + Name: "tempdir, t", + Value: os.TempDir(), + Usage: "Temporary dir path", + }, }, } diff --git a/cmd/serve.go b/cmd/serve.go index dee7ca16d8..75dca222e8 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -15,14 +15,13 @@ import ( "github.com/Unknwon/com" "github.com/go-gitea/git" - gouuid "github.com/satori/go.uuid" - "github.com/urfave/cli" - "github.com/go-gitea/gitea/models" "github.com/go-gitea/gitea/modules/base" "github.com/go-gitea/gitea/modules/httplib" "github.com/go-gitea/gitea/modules/log" "github.com/go-gitea/gitea/modules/setting" + gouuid "github.com/satori/go.uuid" + "github.com/urfave/cli" ) const ( @@ -36,7 +35,11 @@ var CmdServ = cli.Command{ Description: `Serv provide access auth for repositories`, Action: runServ, Flags: []cli.Flag{ - stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"), + cli.StringFlag{ + Name: "config, c", + Value: "custom/conf/app.ini", + Usage: "Custom configuration file path", + }, }, } diff --git a/cmd/update.go b/cmd/update.go index ef494121e9..4a5617cd4f 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -21,7 +21,11 @@ var CmdUpdate = cli.Command{ Description: `Update get pushed info and insert into database`, Action: runUpdate, Flags: []cli.Flag{ - stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"), + cli.StringFlag{ + Name: "config, c", + Value: "custom/conf/app.ini", + Usage: "Custom configuration file path", + }, }, } diff --git a/cmd/web.go b/cmd/web.go index 36425b823d..f3e59b8d4f 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -15,6 +15,7 @@ import ( "path" "strings" + "github.com/go-gitea/git" "github.com/go-gitea/gitea/models" "github.com/go-gitea/gitea/modules/auth" "github.com/go-gitea/gitea/modules/bindata" @@ -38,7 +39,6 @@ import ( "github.com/go-macaron/session" "github.com/go-macaron/toolbox" "github.com/go-xorm/xorm" - "github.com/go-gitea/git" version "github.com/mcuadros/go-version" "github.com/urfave/cli" ini "gopkg.in/ini.v1" @@ -53,8 +53,16 @@ var CmdWeb = cli.Command{ and it takes care of all the other things for you`, Action: runWeb, Flags: []cli.Flag{ - stringFlag("port, p", "3000", "Temporary port number to prevent conflict"), - stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"), + cli.StringFlag{ + Name: "port, p", + Value: "3000", + Usage: "Temporary port number to prevent conflict", + }, + cli.StringFlag{ + Name: "config, c", + Value: "custom/conf/app.ini", + Usage: "Custom configuration file path", + }, }, } From 90fb64b2179c9e700ad87ab0d585825ff16ce5d8 Mon Sep 17 00:00:00 2001 From: Matthias Loibl Date: Wed, 9 Nov 2016 23:32:24 +0100 Subject: [PATCH 2/2] Improve formatting of admin command Signed-off-by: Matthias Loibl --- cmd/admin.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/admin.go b/cmd/admin.go index 5e56f171bf..9c6215fbf7 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -37,11 +37,13 @@ to make automatic initialization process more smoothly`, }, cli.StringFlag{ Name: "password", - Value: "", Usage: "User password", + Value: "", + Usage: "User password", }, cli.StringFlag{ Name: "email", - Value: "", Usage: "User email address", + Value: "", + Usage: "User email address", }, cli.BoolFlag{ Name: "admin",