@@ -10,7 +10,9 @@ import (
1010
1111 "github.com/Bananenpro/cli"
1212 "github.com/code-game-project/codegame-cli-go/new"
13- "github.com/code-game-project/codegame-cli/util"
13+ "github.com/code-game-project/codegame-cli/util/cggenevents"
14+ "github.com/code-game-project/codegame-cli/util/exec"
15+ "github.com/code-game-project/codegame-cli/util/external"
1416)
1517
1618//go:embed templates/main.go.tmpl
@@ -31,73 +33,63 @@ func CreateNewClient(projectName, gameName, serverURL, libraryVersion string, ge
3133 return err
3234 }
3335
34- _ , err = util .Execute (true , "go" , "mod" , "init" , module )
36+ _ , err = exec .Execute (true , "go" , "mod" , "init" , module )
3537 if err != nil {
3638 return err
3739 }
3840
39- libraryURL , libraryTag , err := getGoClientLibraryURL (libraryVersion )
41+ libraryURL , libraryTag , err := getClientLibraryURL (libraryVersion )
4042 if err != nil {
4143 return err
4244 }
4345
4446 cli .BeginLoading ("Installing go-client..." )
45- _ , err = util .Execute (true , "go" , "get" , fmt .Sprintf ("%s@%s" , libraryURL , libraryTag ))
47+ _ , err = exec .Execute (true , "go" , "get" , fmt .Sprintf ("%s@%s" , libraryURL , libraryTag ))
4648 if err != nil {
4749 return err
4850 }
4951 cli .FinishLoading ()
5052
5153 var eventNames []string
5254 if generateWrappers {
53- cgeVersion , err := util .GetCGEVersion (baseURL (serverURL , isSSL (serverURL )))
55+ cgeVersion , err := cggenevents .GetCGEVersion (baseURL (serverURL , isSSL (serverURL )))
5456 if err != nil {
5557 return err
5658 }
5759
58- eventNames , err = util .GetEventNames (baseURL (serverURL , isSSL (serverURL )), cgeVersion )
60+ eventNames , err = cggenevents .GetEventNames (baseURL (serverURL , isSSL (serverURL )), cgeVersion )
5961 if err != nil {
6062 return err
6163 }
6264 }
6365
64- err = createGoClientTemplate (projectName , module , gameName , serverURL , libraryURL , generateWrappers , eventNames )
66+ err = createClientTemplate (projectName , module , gameName , serverURL , libraryURL , generateWrappers , eventNames )
6567 if err != nil {
6668 return err
6769 }
6870
6971 cli .BeginLoading ("Installing dependencies..." )
7072
71- _ , err = util .Execute (true , "go" , "mod" , "tidy" )
73+ _ , err = exec .Execute (true , "go" , "mod" , "tidy" )
7274 if err != nil {
7375 return err
7476 }
7577
7678 cli .FinishLoading ()
77-
7879 return nil
7980}
8081
81- func createGoClientTemplate (projectName , modulePath , gameName , serverURL , libraryURL string , wrappers bool , eventNames []string ) error {
82+ func createClientTemplate (projectName , modulePath , gameName , serverURL , libraryURL string , wrappers bool , eventNames []string ) error {
8283 if ! wrappers {
83- return execGoClientMainTemplate (projectName , serverURL , libraryURL )
84+ return execClientMainTemplate (projectName , serverURL , libraryURL )
8485 }
8586
86- return execGoClientWrappersTemplate (projectName , modulePath , gameName , serverURL , libraryURL , eventNames )
87+ return execClientWrappersTemplate (projectName , modulePath , gameName , serverURL , libraryURL , eventNames )
8788}
8889
89- func getGoClientLibraryURL (clientVersion string ) (url string , tag string , err error ) {
90- if clientVersion == "latest" {
91- var err error
92- clientVersion , err = util .LatestGithubTag ("code-game-project" , "go-client" )
93- if err != nil {
94- return "" , "" , err
95- }
96- clientVersion = strings .TrimPrefix (strings .Join (strings .Split (clientVersion , "." )[:2 ], "." ), "v" )
97- }
98-
90+ func getClientLibraryURL (clientVersion string ) (url string , tag string , err error ) {
9991 majorVersion := strings .Split (clientVersion , "." )[0 ]
100- tag , err = util .GithubTagFromVersion ("code-game-project" , "go-client" , clientVersion )
92+ tag , err = external .GithubTagFromVersion ("code-game-project" , "go-client" , clientVersion )
10193 if err != nil {
10294 return "" , "" , err
10395 }
@@ -109,7 +101,7 @@ func getGoClientLibraryURL(clientVersion string) (url string, tag string, err er
109101 return path , tag , nil
110102}
111103
112- func execGoClientMainTemplate (projectName , serverURL , libraryURL string ) error {
104+ func execClientMainTemplate (projectName , serverURL , libraryURL string ) error {
113105 type data struct {
114106 URL string
115107 LibraryURL string
@@ -121,7 +113,7 @@ func execGoClientMainTemplate(projectName, serverURL, libraryURL string) error {
121113 })
122114}
123115
124- func execGoClientWrappersTemplate (projectName , modulePath , gameName , serverURL , libraryURL string , eventNames []string ) error {
116+ func execClientWrappersTemplate (projectName , modulePath , gameName , serverURL , libraryURL string , eventNames []string ) error {
125117 gamePackageName := strings .ReplaceAll (strings .ReplaceAll (gameName , "-" , "" ), "_" , "" )
126118
127119 gameDir := strings .ReplaceAll (strings .ReplaceAll (gameName , "-" , "" ), "_" , "" )
0 commit comments