cmd is ok

This commit is contained in:
Sense T 2024-04-10 13:24:01 +08:00
parent 9465bb885d
commit 29f75938bb
6 changed files with 87 additions and 100 deletions

View File

@ -2,16 +2,12 @@ package config
import "github.com/urfave/cli/v2"
var Command *cli.Command
func init() {
Command = &cli.Command{
Name: "config",
Usage: "config some settings",
Subcommands: []*cli.Command{
UserCommand,
DatabaseCommand,
DNSCommand,
},
}
var Command = &cli.Command{
Name: "config",
Usage: "config some settings",
Subcommands: []*cli.Command{
UserCommand,
DatabaseCommand,
DNSCommand,
},
}

View File

@ -7,23 +7,19 @@ import (
"github.com/urfave/cli/v2"
)
var DatabaseCommand *cli.Command
var migrationCommand = &cli.Command{
Name: "migrate",
Usage: "migrate database",
Action: migrateDatabase,
}
func init() {
migrationCommand := &cli.Command{
Name: "migrate",
Usage: "migrate database",
Action: migrateDatabase,
}
DatabaseCommand = &cli.Command{
Name: "database",
Usage: "database administration",
Aliases: []string{"db"},
Subcommands: []*cli.Command{
migrationCommand,
},
}
var DatabaseCommand = &cli.Command{
Name: "database",
Usage: "database administration",
Aliases: []string{"db"},
Subcommands: []*cli.Command{
migrationCommand,
},
}
func migrateDatabase(c *cli.Context) error {

View File

@ -5,24 +5,21 @@ import (
"reCoreD-UI/database"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
)
var DNSCommand *cli.Command
func init() {
DNSCommand = &cli.Command{
Name: "dns",
Usage: "Config DNS Settings",
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "servers",
Usage: "dns servers",
Aliases: []string{"s"},
Required: true,
},
},
Action: setDNS,
}
var DNSCommand = &cli.Command{
Name: "dns",
Usage: "Config DNS Settings",
Flags: []cli.Flag{
altsrc.NewStringSliceFlag(&cli.StringSliceFlag{
Name: "servers",
Usage: "dns servers",
Aliases: []string{"s"},
Required: true,
}),
},
Action: setDNS,
}
func setDNS(c *cli.Context) error {

View File

@ -5,32 +5,29 @@ import (
"reCoreD-UI/database"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
)
var UserCommand *cli.Command
func init() {
UserCommand = &cli.Command{
Name: "user",
Usage: "set admin username and password",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "username",
Aliases: []string{"u"},
Value: "amdin",
Usage: "admin username",
EnvVars: []string{"RECORED_ADMIN_USERNAME"},
},
&cli.StringFlag{
Name: "passowrd",
Aliases: []string{"p"},
Required: true,
Usage: "admin password",
EnvVars: []string{"RECORED_ADMIN_PASSWORD"},
},
},
Action: setUser,
}
var UserCommand = &cli.Command{
Name: "user",
Usage: "set admin username and password",
Flags: []cli.Flag{
altsrc.NewStringFlag(&cli.StringFlag{
Name: "username",
Aliases: []string{"u"},
Value: "amdin",
Usage: "admin username",
EnvVars: []string{"RECORED_ADMIN_USERNAME"},
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "passowrd",
Aliases: []string{"p"},
Required: true,
Usage: "admin password",
EnvVars: []string{"RECORED_ADMIN_PASSWORD"},
}),
},
Action: setUser,
}
func setUser(c *cli.Context) error {

View File

@ -4,33 +4,30 @@ import (
webserver "reCoreD-UI/server"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
)
var Command *cli.Command
func init() {
Command = &cli.Command{
Name: "server",
Usage: "run server",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "prefix",
Value: "/",
Usage: "web prefix",
},
&cli.StringFlag{
Name: "listen",
Value: "[::]",
Usage: "IP for listen at",
},
&cli.IntFlag{
Name: "port",
Value: 8080,
Usage: "Port for listen at",
},
},
Action: runServer,
}
var Command = &cli.Command{
Name: "server",
Usage: "run server",
Flags: []cli.Flag{
altsrc.NewStringFlag(&cli.StringFlag{
Name: "prefix",
Value: "/",
Usage: "web prefix",
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "listen",
Value: "[::]",
Usage: "IP for listen at",
}),
altsrc.NewIntFlag(&cli.IntFlag{
Name: "port",
Value: 8080,
Usage: "Port for listen at",
}),
},
Action: runServer,
}
func runServer(c *cli.Context) error {

18
main.go
View File

@ -2,6 +2,8 @@ package main
import (
"os"
"reCoreD-UI/cmd/config"
"reCoreD-UI/cmd/server"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
@ -18,17 +20,14 @@ func main() {
Name: "config",
Usage: "config yaml file",
Aliases: []string{"c"},
Value: "config.yaml",
EnvVars: []string{"RECORED_CONFIG_FILE"},
},
altsrc.NewStringSliceFlag(&cli.StringSliceFlag{}),
&cli.StringFlag{
altsrc.NewStringFlag(&cli.StringFlag{
Name: "mysql-dsn",
Usage: "mysql dsn",
Required: true,
EnvVars: []string{"RECORED_MYSQL_DSN"},
},
&cli.BoolFlag{
}),
altsrc.NewBoolFlag(&cli.BoolFlag{
Name: "debug",
Usage: "enable debug mode",
Value: false,
@ -38,16 +37,21 @@ func main() {
}
return nil
},
},
}),
}
app := &cli.App{
Name: "reCoreD-UI",
Usage: "Web UI for CoreDNS",
UseShortOptionHandling: true,
Before: altsrc.InitInputSourceWithContext(
flags, altsrc.NewYamlSourceFromFlagFunc("config"),
),
Flags: flags,
Commands: []*cli.Command{
server.Command,
config.Command,
},
}
if err := app.Run(os.Args); err != nil {