mirror of
https://github.com/beego/bee.git
synced 2024-11-21 18:40:54 +00:00
bee generate views
This commit is contained in:
parent
270a52100c
commit
6abaa4368b
13
g.go
13
g.go
@ -33,8 +33,8 @@ bee generate migration [filename]
|
||||
bee generate controller [controllerfile]
|
||||
generate RESTFul controllers
|
||||
|
||||
bee generate router [controllerfile]
|
||||
generate router based on controllerfile
|
||||
bee generate view [viewpath]
|
||||
generate CRUD view in viewpath
|
||||
|
||||
bee generate docs
|
||||
generate swagger doc file
|
||||
@ -111,6 +111,15 @@ func generateCode(cmd *Command, args []string) {
|
||||
ColorLog("[HINT] Usage: bee generate controller [filename]\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
case "view":
|
||||
if len(args) == 2 {
|
||||
cname := args[1]
|
||||
generateView(cname, curpath)
|
||||
} else {
|
||||
ColorLog("[ERRO] Wrong number of arguments\n")
|
||||
ColorLog("[HINT] Usage: bee generate view [filename]\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
default:
|
||||
ColorLog("[ERRO] command is missing\n")
|
||||
}
|
||||
|
49
g_views.go
Normal file
49
g_views.go
Normal file
@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
// recipe
|
||||
// admin/recipe
|
||||
func generateView(vpath, crupath string) {
|
||||
absvpath := path.Join(crupath, vpath)
|
||||
os.MkdirAll(absvpath, os.ModePerm)
|
||||
cfile := path.Join(absvpath, "index.tpl")
|
||||
if f, err := os.OpenFile(cfile, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0666); err == nil {
|
||||
defer f.Close()
|
||||
f.WriteString(cfile)
|
||||
ColorLog("[INFO] Created: %v\n", cfile)
|
||||
} else {
|
||||
ColorLog("[ERRO] Could not create view file: %s\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
cfile = path.Join(absvpath, "show.tpl")
|
||||
if f, err := os.OpenFile(cfile, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0666); err == nil {
|
||||
defer f.Close()
|
||||
f.WriteString(cfile)
|
||||
ColorLog("[INFO] Created: %v\n", cfile)
|
||||
} else {
|
||||
ColorLog("[ERRO] Could not create view file: %s\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
cfile = path.Join(absvpath, "create.tpl")
|
||||
if f, err := os.OpenFile(cfile, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0666); err == nil {
|
||||
defer f.Close()
|
||||
f.WriteString(cfile)
|
||||
ColorLog("[INFO] Created: %v\n", cfile)
|
||||
} else {
|
||||
ColorLog("[ERRO] Could not create view file: %s\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
cfile = path.Join(absvpath, "edit.tpl")
|
||||
if f, err := os.OpenFile(cfile, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0666); err == nil {
|
||||
defer f.Close()
|
||||
f.WriteString(cfile)
|
||||
ColorLog("[INFO] Created: %v\n", cfile)
|
||||
} else {
|
||||
ColorLog("[ERRO] Could not create view file: %s\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user