@@ -34,17 +34,18 @@ var CmdApiapp = &commands.Command{
3434 Short : "Creates a Beego API application" ,
3535 Long : `
3636 The command 'api' creates a Beego API application.
37+ now default supoort generate a go modules project.
3738
3839 {{"Example:"|bold}}
39- $ bee api [appname] [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"] [-module=true ] [-beego=v1.12.1]
40+ $ bee api [appname] [-tables=""] [-driver=mysql] [-conn="root:@tcp(127.0.0.1:3306)/test"] [-gopath=false ] [-beego=v1.12.1]
4041
4142 If 'conn' argument is empty, the command will generate an example API application. Otherwise the command
4243 will connect to your database and generate models based on the existing tables.
4344
4445 The command 'api' creates a folder named [appname] with the following structure:
4546
4647 ├── main.go
47- ├── go.mod
48+ ├── go.mod
4849 ├── {{"conf"|foldername}}
4950 │ └── app.conf
5051 ├── {{"controllers"|foldername}}
@@ -543,15 +544,15 @@ func TestGet(t *testing.T) {
543544}
544545
545546`
546- var module utils.DocValue
547+ var gopath utils.DocValue
547548var beegoVersion utils.DocValue
548549
549550func init () {
550551 CmdApiapp .Flag .Var (& generate .Tables , "tables" , "List of table names separated by a comma." )
551552 CmdApiapp .Flag .Var (& generate .SQLDriver , "driver" , "Database driver. Either mysql, postgres or sqlite." )
552553 CmdApiapp .Flag .Var (& generate .SQLConn , "conn" , "Connection string used by the driver to connect to a database instance." )
553- CmdApiapp .Flag .Var (& module , "module " , "Support go modules " )
554- CmdApiapp .Flag .Var (& beegoVersion , "beego" , "set beego version,only take effect by -module=true " )
554+ CmdApiapp .Flag .Var (& gopath , "gopath " , "Support go path,default false " )
555+ CmdApiapp .Flag .Var (& beegoVersion , "beego" , "set beego version,only take effect by go mod " )
555556 commands .AvailableCommands = append (commands .AvailableCommands , CmdApiapp )
556557}
557558
@@ -563,14 +564,15 @@ func createAPI(cmd *commands.Command, args []string) int {
563564 }
564565
565566 if len (args ) >= 2 {
566- cmd .Flag .Parse (args [1 :])
567- } else {
568- module = "false"
567+ err := cmd .Flag .Parse (args [1 :])
568+ if err != nil {
569+ beeLogger .Log .Fatal ("Parse args err " + err .Error ())
570+ }
569571 }
570572 var appPath string
571573 var packPath string
572574 var err error
573- if module ! = `true` {
575+ if gopath = = `true` {
574576 beeLogger .Log .Info ("generate api project support GOPATH" )
575577 version .ShowShortVersionBanner ()
576578 appPath , packPath , err = utils .CheckEnv (args [0 ])
@@ -605,7 +607,7 @@ func createAPI(cmd *commands.Command, args []string) int {
605607 beeLogger .Log .Info ("Creating API..." )
606608
607609 os .MkdirAll (appPath , 0755 )
608- if module = = `true` { //generate first for calc model name
610+ if gopath ! = `true` { //generate first for calc model name
609611 fmt .Fprintf (output , "\t %s%screate%s\t %s%s\n " , "\x1b [32m" , "\x1b [1m" , "\x1b [21m" , path .Join (appPath , "go.mod" ), "\x1b [0m" )
610612 utils .WriteToFile (path .Join (appPath , "go.mod" ), fmt .Sprintf (goMod , packPath , utils .GetGoVersionSkipMinor (), beegoVersion .String ()))
611613 }
0 commit comments