Use cli Flags directly and not some helper funcs
Signed-off-by: Matthias Loibl <mail@matthiasloibl.com>
This commit is contained in:
parent
475ddd8d89
commit
5cd093aa46
8 changed files with 91 additions and 69 deletions
27
cmd/admin.go
27
cmd/admin.go
|
@ -30,11 +30,28 @@ to make automatic initialization process more smoothly`,
|
||||||
Usage: "Create a new user in database",
|
Usage: "Create a new user in database",
|
||||||
Action: runCreateUser,
|
Action: runCreateUser,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
stringFlag("name", "", "Username"),
|
cli.StringFlag{
|
||||||
stringFlag("password", "", "User password"),
|
Name: "name",
|
||||||
stringFlag("email", "", "User email address"),
|
Value: "",
|
||||||
boolFlag("admin", "User is an admin"),
|
Usage: "Username",
|
||||||
stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"),
|
},
|
||||||
|
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",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
35
cmd/cert.go
35
cmd/cert.go
|
@ -33,12 +33,35 @@ var CmdCert = cli.Command{
|
||||||
Outputs to 'cert.pem' and 'key.pem' and will overwrite existing files.`,
|
Outputs to 'cert.pem' and 'key.pem' and will overwrite existing files.`,
|
||||||
Action: runCert,
|
Action: runCert,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
stringFlag("host", "", "Comma-separated hostnames and IPs to generate a certificate for"),
|
cli.StringFlag{
|
||||||
stringFlag("ecdsa-curve", "", "ECDSA curve to use to generate a key. Valid values are P224, P256, P384, P521"),
|
Name: "host",
|
||||||
intFlag("rsa-bits", 2048, "Size of RSA key to generate. Ignored if --ecdsa-curve is set"),
|
Value: "",
|
||||||
stringFlag("start-date", "", "Creation date formatted as Jan 1 15:04:05 2011"),
|
Usage: "Comma-separated hostnames and IPs to generate a certificate for",
|
||||||
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: "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",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ var CmdCert = cli.Command{
|
||||||
Action: runCert,
|
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.")
|
fmt.Println("Command cert not available, please use build tags 'cert' to rebuild.")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
||||||
|
|
42
cmd/cmd.go
42
cmd/cmd.go
|
@ -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,
|
|
||||||
}
|
|
||||||
}
|
|
23
cmd/dump.go
23
cmd/dump.go
|
@ -6,18 +6,16 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"io/ioutil"
|
|
||||||
|
|
||||||
"github.com/Unknwon/cae/zip"
|
"github.com/Unknwon/cae/zip"
|
||||||
"github.com/urfave/cli"
|
|
||||||
|
|
||||||
"github.com/go-gitea/gitea/models"
|
"github.com/go-gitea/gitea/models"
|
||||||
"github.com/go-gitea/gitea/modules/setting"
|
"github.com/go-gitea/gitea/modules/setting"
|
||||||
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CmdDump represents the available dump sub-command.
|
// 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`,
|
It can be used for backup and capture Gogs server image to send to maintainer`,
|
||||||
Action: runDump,
|
Action: runDump,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"),
|
cli.StringFlag{
|
||||||
boolFlag("verbose, v", "Show process details"),
|
Name: "config, c",
|
||||||
stringFlag("tempdir, t", os.TempDir(), "Temporary dir path"),
|
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",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
cmd/serve.go
11
cmd/serve.go
|
@ -15,14 +15,13 @@ import (
|
||||||
|
|
||||||
"github.com/Unknwon/com"
|
"github.com/Unknwon/com"
|
||||||
"github.com/go-gitea/git"
|
"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/models"
|
||||||
"github.com/go-gitea/gitea/modules/base"
|
"github.com/go-gitea/gitea/modules/base"
|
||||||
"github.com/go-gitea/gitea/modules/httplib"
|
"github.com/go-gitea/gitea/modules/httplib"
|
||||||
"github.com/go-gitea/gitea/modules/log"
|
"github.com/go-gitea/gitea/modules/log"
|
||||||
"github.com/go-gitea/gitea/modules/setting"
|
"github.com/go-gitea/gitea/modules/setting"
|
||||||
|
gouuid "github.com/satori/go.uuid"
|
||||||
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -36,7 +35,11 @@ var CmdServ = cli.Command{
|
||||||
Description: `Serv provide access auth for repositories`,
|
Description: `Serv provide access auth for repositories`,
|
||||||
Action: runServ,
|
Action: runServ,
|
||||||
Flags: []cli.Flag{
|
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",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,11 @@ var CmdUpdate = cli.Command{
|
||||||
Description: `Update get pushed info and insert into database`,
|
Description: `Update get pushed info and insert into database`,
|
||||||
Action: runUpdate,
|
Action: runUpdate,
|
||||||
Flags: []cli.Flag{
|
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",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
cmd/web.go
14
cmd/web.go
|
@ -15,6 +15,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/go-gitea/git"
|
||||||
"github.com/go-gitea/gitea/models"
|
"github.com/go-gitea/gitea/models"
|
||||||
"github.com/go-gitea/gitea/modules/auth"
|
"github.com/go-gitea/gitea/modules/auth"
|
||||||
"github.com/go-gitea/gitea/modules/bindata"
|
"github.com/go-gitea/gitea/modules/bindata"
|
||||||
|
@ -38,7 +39,6 @@ import (
|
||||||
"github.com/go-macaron/session"
|
"github.com/go-macaron/session"
|
||||||
"github.com/go-macaron/toolbox"
|
"github.com/go-macaron/toolbox"
|
||||||
"github.com/go-xorm/xorm"
|
"github.com/go-xorm/xorm"
|
||||||
"github.com/go-gitea/git"
|
|
||||||
version "github.com/mcuadros/go-version"
|
version "github.com/mcuadros/go-version"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
ini "gopkg.in/ini.v1"
|
ini "gopkg.in/ini.v1"
|
||||||
|
@ -53,8 +53,16 @@ var CmdWeb = cli.Command{
|
||||||
and it takes care of all the other things for you`,
|
and it takes care of all the other things for you`,
|
||||||
Action: runWeb,
|
Action: runWeb,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
stringFlag("port, p", "3000", "Temporary port number to prevent conflict"),
|
cli.StringFlag{
|
||||||
stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"),
|
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",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue