Use cli Flags directly and not some helper funcs

Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>
release/v1.15
Matthias Loibl 2016-11-09 23:18:22 +01:00
parent 475ddd8d89
commit 5cd093aa46
8 changed files with 91 additions and 69 deletions

View File

@ -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",
},
},
}
)

View File

@ -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",
},
},
}

View File

@ -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)

View File

@ -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,
}
}

View File

@ -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",
},
},
}

View File

@ -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",
},
},
}

View File

@ -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",
},
},
}

View File

@ -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",
},
},
}