Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add evm start and celestia-devnet start commands #15

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions cmd/world/cardinal/cardinal.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,27 @@ import (
"pkg.world.dev/world-cli/tea/style"
)

func init() {
// Register subcommands - `world cardinal [subcommand]`
BaseCmd.AddCommand(createCmd, startCmd, devCmd, restartCmd, purgeCmd, stopCmd)
}

// BaseCmd is the base command for the cardinal subcommand
// Usage: `world cardinal`
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",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
func BaseCmd() *cobra.Command {
base := &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",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return dependency.Check(
dependency.Go,
dependency.Git,
dependency.Docker,
dependency.DockerCompose,
dependency.DockerDaemon,
)
},
Run: func(cmd *cobra.Command, args []string) {
if err := cmd.Help(); err != nil {
log.Fatal().Err(err).Msg("Failed to execute cardinal command")
}
},
},Run: func(cmd *cobra.Command, args []string) {
if err := cmd.Help(); err != nil {
log.Fatal().Err(err).Msg("Failed to execute cardinal command")
}
},
}
base.AddCommand(createCmd, StartCmd(), devCmd, restartCmd, purgeCmd, stopCmd)
return base
}
17 changes: 11 additions & 6 deletions cmd/world/cardinal/create.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package cardinal

import (
"pkg.world.dev/world-cli/common/dependency"
"strings"

"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
"github.com/spf13/cobra"
"pkg.world.dev/world-cli/common/tea_cmd"
"pkg.world.dev/world-cli/common/teacmd"
"pkg.world.dev/world-cli/tea/component/steps"
"pkg.world.dev/world-cli/tea/style"
)

const TemplateGitUrl = "https://github.com/Argus-Labs/starter-game-template.git"

var CreateDeps = []dependency.Dependency{
dependency.Git,
}

/////////////////
// Cobra Setup //
/////////////////
Expand Down Expand Up @@ -44,7 +49,7 @@ type WorldCreateModel struct {
steps steps.Model
projectNameInput textinput.Model
args []string
depStatus []tea_cmd.DependencyStatus
depStatus []teacmd.DependencyStatus
depStatusErr error
err error
}
Expand Down Expand Up @@ -90,7 +95,7 @@ func (m WorldCreateModel) Init() tea.Cmd {
// Update handles incoming events and updates the model accordingly
func (m WorldCreateModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea_cmd.CheckDependenciesMsg:
case teacmd.CheckDependenciesMsg:
m.depStatus = msg.DepStatus
m.depStatusErr = msg.Err
if msg.Err != nil {
Expand Down Expand Up @@ -120,7 +125,7 @@ func (m WorldCreateModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if msg.Index == 1 {
return m, tea.Sequence(
NewLogCmd(style.ChevronIcon.Render()+"Cloning starter-game-template..."),
tea_cmd.GitCloneCmd(TemplateGitUrl, m.projectNameInput.Value(), "Initial commit from World CLI"),
teacmd.GitCloneCmd(TemplateGitUrl, m.projectNameInput.Value(), "Initial commit from World CLI"),
)
}
return m, nil
Expand All @@ -139,7 +144,7 @@ func (m WorldCreateModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// All done, quit
return m, tea.Quit

case tea_cmd.GitCloneFinishMsg:
case teacmd.GitCloneFinishMsg:
// If there is an error, log stderr then mark step as failed
if msg.Err != nil {
m.logs = append(m.logs, style.CrossIcon.Render()+msg.Err.Error())
Expand All @@ -163,7 +168,7 @@ func (m WorldCreateModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// View renders the UI based on the data in the WorldCreateModel
func (m WorldCreateModel) View() string {
if m.depStatusErr != nil {
return tea_cmd.PrettyPrintMissingDependency(m.depStatus)
return teacmd.PrettyPrintMissingDependency(m.depStatus)
}

output := ""
Expand Down
2 changes: 1 addition & 1 deletion cmd/world/cardinal/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func runRedis() error {
func runCardinal() (*exec.Cmd, error) {
err := os.Chdir("cardinal")
if err != nil {
return nil, errors.New("can't find cardinal directory. Are you in the root of a World Engine project")
return nil, errors.New("can't find cardinal directory. Are you in the root of a World Engine project?")
}

env := map[string]string{
Expand Down
4 changes: 2 additions & 2 deletions cmd/world/cardinal/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cardinal

import (
"github.com/spf13/cobra"
"pkg.world.dev/world-cli/common/tea_cmd"
"pkg.world.dev/world-cli/common/teacmd"
)

/////////////////
Expand All @@ -17,7 +17,7 @@ var purgeCmd = &cobra.Command{
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()
err := teacmd.DockerPurge()
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/world/cardinal/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cardinal

import (
"github.com/spf13/cobra"
"pkg.world.dev/world-cli/common/tea_cmd"
"pkg.world.dev/world-cli/common/teacmd"
)

/////////////////
Expand All @@ -20,9 +20,9 @@ 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,
err := teacmd.DockerRestart(true, []teacmd.DockerService{
teacmd.DockerServiceCardinal,
teacmd.DockerServiceNakama,
})
if err != nil {
return err
Expand Down
79 changes: 39 additions & 40 deletions cmd/world/cardinal/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,55 @@ package cardinal
import (
"fmt"
"github.com/spf13/cobra"
"pkg.world.dev/world-cli/common/tea_cmd"
"pkg.world.dev/world-cli/common/teacmd"
)

/////////////////
// Cobra Setup //
/////////////////

func init() {
startCmd.Flags().Bool("build", true, "Rebuild Docker images before starting")
startCmd.Flags().Bool("debug", false, "Run in debug mode")
startCmd.Flags().Bool("detach", false, "Run in detached mode")
}

// startCmd starts your Cardinal game shard stack
// Usage: `world cardinal start`
var startCmd = &cobra.Command{
Use: "start",
Short: "Start your Cardinal game shard stack",
Long: `Start your Cardinal game shard stack.
// StartCmd returns a command that starts your Cardinal game shard stack.
func StartCmd() *cobra.Command {
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 and its dependencies:
- Cardinal (Core game logic)
- Nakama (Relay)
- Redis (Cardinal dependency)
- Postgres (Nakama dependency)`,
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
}

detachFlag, err := cmd.Flags().GetBool("detach")
if err != nil {
return err
}

fmt.Println("Starting Cardinal game shard...")
fmt.Println("This may take a few minutes to rebuild the Docker images.")
fmt.Println("Use `world cardinal dev` to run Cardinal faster/easier in development mode.")

err = tea_cmd.DockerStartAll(buildFlag, debugFlag, detachFlag, -1)
if err != nil {
return err
}

return nil
},
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
}

detachFlag, err := cmd.Flags().GetBool("detach")
if err != nil {
return err
}

fmt.Println("Starting Cardinal game shard...")
fmt.Println("This may take a few minutes to rebuild the Docker images.")
fmt.Println("Use `world cardinal dev` to run Cardinal faster/easier in development mode.")

err = teacmd.DockerStartAll(buildFlag, debugFlag, detachFlag, -1)
if err != nil {
return err
}

return nil
},
}
startCmd.Flags().Bool("build", true, "Rebuild Docker images before starting")
startCmd.Flags().Bool("debug", false, "Run in debug mode")
startCmd.Flags().Bool("detach", false, "Run in detached mode")
return startCmd
}
4 changes: 2 additions & 2 deletions cmd/world/cardinal/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cardinal

import (
"github.com/spf13/cobra"
"pkg.world.dev/world-cli/common/tea_cmd"
"pkg.world.dev/world-cli/common/teacmd"
)

/////////////////
Expand All @@ -22,7 +22,7 @@ This will stop the following Docker services:
- Redis (Cardinal dependency)
- Postgres (Nakama dependency)`,
RunE: func(cmd *cobra.Command, args []string) error {
err := tea_cmd.DockerStopAll()
err := teacmd.DockerStopAll()
if err != nil {
return err
}
Expand Down
Loading