Skip to content

Commit 145648a

Browse files
authored
Merge pull request #127 from metalmatze/enhancement/cli
Use cli Flags directly and not some helper funcs
2 parents 475ddd8 + 90fb64b commit 145648a

File tree

8 files changed

+93
-69
lines changed

8 files changed

+93
-69
lines changed

cmd/admin.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,30 @@ to make automatic initialization process more smoothly`,
3030
Usage: "Create a new user in database",
3131
Action: runCreateUser,
3232
Flags: []cli.Flag{
33-
stringFlag("name", "", "Username"),
34-
stringFlag("password", "", "User password"),
35-
stringFlag("email", "", "User email address"),
36-
boolFlag("admin", "User is an admin"),
37-
stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"),
33+
cli.StringFlag{
34+
Name: "name",
35+
Value: "",
36+
Usage: "Username",
37+
},
38+
cli.StringFlag{
39+
Name: "password",
40+
Value: "",
41+
Usage: "User password",
42+
},
43+
cli.StringFlag{
44+
Name: "email",
45+
Value: "",
46+
Usage: "User email address",
47+
},
48+
cli.BoolFlag{
49+
Name: "admin",
50+
Usage: "User is an admin",
51+
},
52+
cli.StringFlag{
53+
Name: "config, c",
54+
Value: "custom/conf/app.ini",
55+
Usage: "Custom configuration file path",
56+
},
3857
},
3958
}
4059
)

cmd/cert.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,35 @@ var CmdCert = cli.Command{
3333
Outputs to 'cert.pem' and 'key.pem' and will overwrite existing files.`,
3434
Action: runCert,
3535
Flags: []cli.Flag{
36-
stringFlag("host", "", "Comma-separated hostnames and IPs to generate a certificate for"),
37-
stringFlag("ecdsa-curve", "", "ECDSA curve to use to generate a key. Valid values are P224, P256, P384, P521"),
38-
intFlag("rsa-bits", 2048, "Size of RSA key to generate. Ignored if --ecdsa-curve is set"),
39-
stringFlag("start-date", "", "Creation date formatted as Jan 1 15:04:05 2011"),
40-
durationFlag("duration", 365*24*time.Hour, "Duration that certificate is valid for"),
41-
boolFlag("ca", "whether this cert should be its own Certificate Authority"),
36+
cli.StringFlag{
37+
Name: "host",
38+
Value: "",
39+
Usage: "Comma-separated hostnames and IPs to generate a certificate for",
40+
},
41+
cli.StringFlag{
42+
Name: "ecdsa-curve",
43+
Value: "",
44+
Usage: "ECDSA curve to use to generate a key. Valid values are P224, P256, P384, P521",
45+
},
46+
cli.IntFlag{
47+
Name: "rsa-bits",
48+
Value: 2048,
49+
Usage: "Size of RSA key to generate. Ignored if --ecdsa-curve is set",
50+
},
51+
cli.StringFlag{
52+
Name: "start-date",
53+
Value: "",
54+
Usage: "Creation date formatted as Jan 1 15:04:05 2011",
55+
},
56+
cli.DurationFlag{
57+
Name: "duration",
58+
Value: 365 * 24 * time.Hour,
59+
Usage: "Duration that certificate is valid for",
60+
},
61+
cli.BoolFlag{
62+
Name: "ca",
63+
Usage: "whether this cert should be its own Certificate Authority",
64+
},
4265
},
4366
}
4467

cmd/cert_stub.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var CmdCert = cli.Command{
2222
Action: runCert,
2323
}
2424

25-
func runCert(ctx *cli.Context) error {
25+
func runCert(*cli.Context) error {
2626
fmt.Println("Command cert not available, please use build tags 'cert' to rebuild.")
2727
os.Exit(1)
2828

cmd/cmd.go

Lines changed: 0 additions & 42 deletions
This file was deleted.

cmd/dump.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ package cmd
66

77
import (
88
"fmt"
9+
"io/ioutil"
910
"log"
1011
"os"
1112
"path"
1213
"time"
1314

14-
"io/ioutil"
15-
1615
"github.com/Unknwon/cae/zip"
17-
"github.com/urfave/cli"
18-
1916
"github.com/go-gitea/gitea/models"
2017
"github.com/go-gitea/gitea/modules/setting"
18+
"github.com/urfave/cli"
2119
)
2220

2321
// CmdDump represents the available dump sub-command.
@@ -28,9 +26,20 @@ var CmdDump = cli.Command{
2826
It can be used for backup and capture Gogs server image to send to maintainer`,
2927
Action: runDump,
3028
Flags: []cli.Flag{
31-
stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"),
32-
boolFlag("verbose, v", "Show process details"),
33-
stringFlag("tempdir, t", os.TempDir(), "Temporary dir path"),
29+
cli.StringFlag{
30+
Name: "config, c",
31+
Value: "custom/conf/app.ini",
32+
Usage: "Custom configuration file path",
33+
},
34+
cli.BoolFlag{
35+
Name: "verbose, v",
36+
Usage: "Show process details",
37+
},
38+
cli.StringFlag{
39+
Name: "tempdir, t",
40+
Value: os.TempDir(),
41+
Usage: "Temporary dir path",
42+
},
3443
},
3544
}
3645

cmd/serve.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ import (
1515

1616
"github.com/Unknwon/com"
1717
"github.com/go-gitea/git"
18-
gouuid "github.com/satori/go.uuid"
19-
"github.com/urfave/cli"
20-
2118
"github.com/go-gitea/gitea/models"
2219
"github.com/go-gitea/gitea/modules/base"
2320
"github.com/go-gitea/gitea/modules/httplib"
2421
"github.com/go-gitea/gitea/modules/log"
2522
"github.com/go-gitea/gitea/modules/setting"
23+
gouuid "github.com/satori/go.uuid"
24+
"github.com/urfave/cli"
2625
)
2726

2827
const (
@@ -36,7 +35,11 @@ var CmdServ = cli.Command{
3635
Description: `Serv provide access auth for repositories`,
3736
Action: runServ,
3837
Flags: []cli.Flag{
39-
stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"),
38+
cli.StringFlag{
39+
Name: "config, c",
40+
Value: "custom/conf/app.ini",
41+
Usage: "Custom configuration file path",
42+
},
4043
},
4144
}
4245

cmd/update.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ var CmdUpdate = cli.Command{
2121
Description: `Update get pushed info and insert into database`,
2222
Action: runUpdate,
2323
Flags: []cli.Flag{
24-
stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"),
24+
cli.StringFlag{
25+
Name: "config, c",
26+
Value: "custom/conf/app.ini",
27+
Usage: "Custom configuration file path",
28+
},
2529
},
2630
}
2731

cmd/web.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"path"
1616
"strings"
1717

18+
"github.com/go-gitea/git"
1819
"github.com/go-gitea/gitea/models"
1920
"github.com/go-gitea/gitea/modules/auth"
2021
"github.com/go-gitea/gitea/modules/bindata"
@@ -38,7 +39,6 @@ import (
3839
"github.com/go-macaron/session"
3940
"github.com/go-macaron/toolbox"
4041
"github.com/go-xorm/xorm"
41-
"github.com/go-gitea/git"
4242
version "github.com/mcuadros/go-version"
4343
"github.com/urfave/cli"
4444
ini "gopkg.in/ini.v1"
@@ -53,8 +53,16 @@ var CmdWeb = cli.Command{
5353
and it takes care of all the other things for you`,
5454
Action: runWeb,
5555
Flags: []cli.Flag{
56-
stringFlag("port, p", "3000", "Temporary port number to prevent conflict"),
57-
stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"),
56+
cli.StringFlag{
57+
Name: "port, p",
58+
Value: "3000",
59+
Usage: "Temporary port number to prevent conflict",
60+
},
61+
cli.StringFlag{
62+
Name: "config, c",
63+
Value: "custom/conf/app.ini",
64+
Usage: "Custom configuration file path",
65+
},
5866
},
5967
}
6068

0 commit comments

Comments
 (0)