-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cardinal subcommand to start/stop/restart/purge (#9)
Co-authored-by: Tyler <[email protected]>
- Loading branch information
1 parent
1ef5889
commit 702bd0a
Showing
33 changed files
with
401 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cardinal | ||
|
||
import ( | ||
"github.com/rs/zerolog/log" | ||
"github.com/spf13/cobra" | ||
"pkg.world.dev/world-cli/tea/style" | ||
) | ||
|
||
func init() { | ||
// Register subcommands - `world cardinal [subcommand]` | ||
BaseCmd.AddCommand(createCmd, startCmd, restartCmd, purgeCmd, stopCmd) | ||
} | ||
|
||
var BaseCmd = &cobra.Command{ | ||
Use: "cardinal", | ||
Short: "Manage your Cardinal game shard project", | ||
Long: style.CLIHeader("World CLI — CARDINAL", "Manage your Cardinal game shard project"), | ||
GroupID: "Core", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := cmd.Help(); err != nil { | ||
log.Fatal().Err(err).Msg("Failed to execute cardinal command") | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cardinal | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"pkg.world.dev/world-cli/common/tea_cmd" | ||
) | ||
|
||
///////////////// | ||
// Cobra Setup // | ||
///////////////// | ||
|
||
var purgeCmd = &cobra.Command{ | ||
Use: "purge", | ||
Short: "Stop and reset the state of your Cardinal game shard", | ||
Long: `Stop and reset the state of your Cardinal game shard. | ||
This command stop all Docker services and remove all Docker volumes.`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
err := tea_cmd.DockerPurge() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cardinal | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"pkg.world.dev/world-cli/common/tea_cmd" | ||
) | ||
|
||
///////////////// | ||
// Cobra Setup // | ||
///////////////// | ||
|
||
var restartCmd = &cobra.Command{ | ||
Use: "restart", | ||
Short: "Restart your Cardinal game shard stack", | ||
Long: `Restart your Cardinal game shard stack. | ||
This will restart the following Docker services: | ||
- Cardinal (Core game logic) | ||
- Nakama (Relay)`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
err := tea_cmd.DockerRestart(true, []tea_cmd.DockerService{ | ||
tea_cmd.DockerServiceCardinal, | ||
tea_cmd.DockerServiceNakama, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package cardinal | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"pkg.world.dev/world-cli/common/tea_cmd" | ||
) | ||
|
||
///////////////// | ||
// Cobra Setup // | ||
///////////////// | ||
|
||
func init() { | ||
startCmd.Flags().Bool("build", true, "Rebuild the Docker images before starting") | ||
startCmd.Flags().Bool("debug", false, "Enable debug mode") | ||
startCmd.Flags().String("mode", "", "Run with special mode [detach/integration-test]") | ||
} | ||
|
||
var startCmd = &cobra.Command{ | ||
Use: "start", | ||
Short: "Start your Cardinal game shard stack", | ||
Long: `Start your Cardinal game shard stack. | ||
This will start the following Docker services: | ||
- Cardinal (Core game logic) | ||
- Nakama (Relay)`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
buildFlag, err := cmd.Flags().GetBool("build") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
debugFlag, err := cmd.Flags().GetBool("debug") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
modeFlag, err := cmd.Flags().GetString("mode") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Don't allow running with special mode and debug mode | ||
if modeFlag != "" && debugFlag { | ||
return fmt.Errorf("cannot run with special mode and debug mode at the same time") | ||
} | ||
|
||
switch modeFlag { | ||
case "": | ||
if debugFlag { | ||
err = tea_cmd.DockerStartDebug() | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
err = tea_cmd.DockerStart(buildFlag, []tea_cmd.DockerService{tea_cmd.DockerServiceCardinal, tea_cmd.DockerServiceNakama}) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
case "detach": | ||
err = tea_cmd.DockerStartDetach() | ||
if err != nil { | ||
return err | ||
} | ||
case "integration-test": | ||
err = tea_cmd.DockerStartTest() | ||
if err != nil { | ||
return err | ||
} | ||
default: | ||
return fmt.Errorf("unknown mode %s", modeFlag) | ||
} | ||
|
||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cardinal | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"pkg.world.dev/world-cli/common/tea_cmd" | ||
) | ||
|
||
///////////////// | ||
// Cobra Setup // | ||
///////////////// | ||
|
||
var stopCmd = &cobra.Command{ | ||
Use: "stop", | ||
Short: "Stop your Cardinal game shard stack", | ||
Long: `Stop your Cardinal game shard stack. | ||
This will stop the following Docker services: | ||
- Cardinal (Core game logic) | ||
- Nakama (Relay)`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
err := tea_cmd.DockerStop([]tea_cmd.DockerService{ | ||
tea_cmd.DockerServiceCardinal, | ||
tea_cmd.DockerServiceNakama, | ||
tea_cmd.DockerServicePostgres, | ||
tea_cmd.DockerServiceRedis, | ||
tea_cmd.DockerServiceTestsuite, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} |
Oops, something went wrong.