Skip to content

Commit

Permalink
feat: 添加new命令
Browse files Browse the repository at this point in the history
  • Loading branch information
2637309949 committed Jul 1, 2021
1 parent 7e123bd commit 649b1f2
Show file tree
Hide file tree
Showing 7 changed files with 559 additions and 548 deletions.
22 changes: 14 additions & 8 deletions cmd/dolphin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

// InitViper defined
func InitViper(cmd *cobra.Command, args []string) {
func InitViper(cmd *cobra.Command, _ []string) {
utils.SetFormatter(terminal.IsTerminal(unix.Stdout))
utils.SetLevel(cmd)
viper.SetConfigName("app")
Expand Down Expand Up @@ -88,14 +88,14 @@ var (
rootCmd = &cobra.Command{
Use: "dolphin",
Short: "dol",
Long: `dolphin, a cli tools for generate golang code`,
Long: `dolphin, a code generation tool for golang`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
InitViper(cmd, args)
},
}
build = &cobra.Command{
Use: "build",
Short: "Build project from xml",
Short: "build from the configuration file",
RunE: func(_ *cobra.Command, args []string) error {
wd, err := os.Getwd()
justOne := false
Expand Down Expand Up @@ -128,7 +128,7 @@ var (
}
clean = &cobra.Command{
Use: "clean",
Short: "Removing intermediate files",
Short: "remove temp file, such as *.go.new",
RunE: func(*cobra.Command, []string) error {
wd, err := os.Getwd()
if err != nil {
Expand All @@ -140,7 +140,7 @@ var (
}
more = &cobra.Command{
Use: "more",
Short: "Add controller and table",
Short: "add controller and table",
RunE: func(_ *cobra.Command, args []string) error {
wd, err := os.Getwd()
if err != nil {
Expand All @@ -153,13 +153,18 @@ var (
},
}
setup = &cobra.Command{
Use: "init",
Short: "Initialize a empty project",
Use: "new",
Short: "new a empty project",
RunE: func(_ *cobra.Command, args []string) error {
wd, err := os.Getwd()
if err != nil {
return err
}
if len(args) < 1 {
logrus.Warn("please provide the project name")
return nil
}
wd = path.Join(wd, args[0])
if files, _ := utils.WalkFileInDirWithSuffix(wd, ".xml"); len(files) == 0 {
p := parser.NewTpl(path.Base(wd), path.Base(wd))
if err := p.Walk(wd); err != nil {
Expand All @@ -172,8 +177,9 @@ var (
return err
}
} else {
logrus.Warn("It is not allowed to initialize a non-empty project")
logrus.Warn("it is not allowed to initialize a non-empty project")
}
logrus.Infof("new project success, cd to %v dir and run `dolphin build`", args[0])
return nil
},
}
Expand Down
304 changes: 0 additions & 304 deletions cmd/dolphin/schema/common.go

This file was deleted.

Loading

0 comments on commit 649b1f2

Please sign in to comment.