66 "net/http"
77
88 "github.com/Bananenpro/cli"
9+ "github.com/code-game-project/go-utils/config"
10+ "github.com/code-game-project/go-utils/external"
911 "github.com/code-game-project/go-utils/sessions"
1012 "github.com/google/uuid"
1113 "github.com/spf13/cobra"
@@ -14,7 +16,7 @@ import (
1416// shareGameCmd represents the share game command
1517var shareGameCmd = & cobra.Command {
1618 Use : "game" ,
17- Short : "Share a game with share.code-game.org ." ,
19+ Short : "Share a game with CodeGame Share ." ,
1820 Args : cobra .RangeArgs (0 , 2 ),
1921 Run : func (cmd * cobra.Command , args []string ) {
2022 var gameURL string
@@ -94,7 +96,11 @@ var shareGameCmd = &cobra.Command{
9496 jsonData , err := json .Marshal (data )
9597 abort (err )
9698
97- resp , err := http .Post ("https://share.code-game.org/game" , "application/json" , bytes .NewBuffer (jsonData ))
99+ conf := config .Load ()
100+ shareURL := external .TrimURL (conf .ShareURL )
101+ baseURL := external .BaseURL ("http" , external .IsTLS (shareURL ), shareURL )
102+
103+ resp , err := http .Post (baseURL + "/game" , "application/json" , bytes .NewBuffer (jsonData ))
98104 if err != nil {
99105 cli .Error ("Failed to upload data: %s" , err )
100106 return
@@ -116,7 +122,7 @@ var shareGameCmd = &cobra.Command{
116122 err = json .NewDecoder (resp .Body ).Decode (& res )
117123 abortf ("Failed to decode server response: %s" , err )
118124 cli .Success ("Success! You can view the game details with the following link:" )
119- cli .PrintColor (cli .Cyan , "https://share.code-game.org /%s" , res .Id )
125+ cli .PrintColor (cli .Cyan , baseURL + " /%s" , res .Id )
120126 },
121127}
122128
0 commit comments