-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor and use kong for cli command parsing (#10)
- Loading branch information
1 parent
b86d271
commit 2e54555
Showing
34 changed files
with
405 additions
and
433 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
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,55 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/customrealms/cli/internal/actions/build" | ||
"github.com/customrealms/cli/internal/project" | ||
) | ||
|
||
type BuildCmd struct { | ||
ProjectDir string `name:"project" short:"p" usage:"plugin project directory" optional:""` | ||
McVersion string `name:"mc" usage:"Minecraft version number target" optional:""` | ||
TemplateJarFile string `name:"jar" short:"t" usage:"template JAR file" optional:""` | ||
OutputFile string `name:"output" short:"o" usage:"output JAR file path"` | ||
} | ||
|
||
func (c *BuildCmd) Run() error { | ||
// Root context for the CLI | ||
ctx, cancel := rootContext() | ||
defer cancel() | ||
|
||
// Default to the current working directory | ||
if c.ProjectDir == "" { | ||
c.ProjectDir, _ = os.Getwd() | ||
} | ||
|
||
// Get the Minecraft version | ||
minecraftVersion := mustMinecraftVersion(ctx, c.McVersion) | ||
|
||
// Create the JAR template to build with | ||
var jarTemplate build.JarTemplate | ||
if len(c.TemplateJarFile) > 0 { | ||
jarTemplate = &build.FileJarTemplate{ | ||
Filename: c.TemplateJarFile, | ||
} | ||
} else { | ||
jarTemplate = &build.GitHubJarTemplate{ | ||
MinecraftVersion: minecraftVersion, | ||
} | ||
} | ||
|
||
// Create the project | ||
crProject := project.Project{ | ||
Dir: c.ProjectDir, | ||
} | ||
|
||
// Create the build action | ||
buildAction := build.BuildAction{ | ||
Project: &crProject, | ||
JarTemplate: jarTemplate, | ||
MinecraftVersion: minecraftVersion, | ||
OutputFile: c.OutputFile, | ||
} | ||
return buildAction.Run(ctx) | ||
} |
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 main | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/customrealms/cli/internal/actions/initialize" | ||
) | ||
|
||
type InitCmd struct { | ||
ProjectDir string `name:"project" short:"p" usage:"plugin project directory" optional:""` | ||
} | ||
|
||
func (c *InitCmd) Run() error { | ||
// Root context for the CLI | ||
ctx, cancel := rootContext() | ||
defer cancel() | ||
|
||
// Default to the current working directory | ||
if c.ProjectDir == "" { | ||
c.ProjectDir, _ = os.Getwd() | ||
} | ||
|
||
// Create the init runner | ||
initAction := initialize.InitAction{ | ||
Name: filepath.Base(c.ProjectDir), | ||
Dir: c.ProjectDir, | ||
Template: nil, | ||
} | ||
return initAction.Run(ctx) | ||
} |
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,80 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/customrealms/cli/internal/actions/build" | ||
"github.com/customrealms/cli/internal/actions/serve" | ||
"github.com/customrealms/cli/internal/project" | ||
"github.com/customrealms/cli/internal/server" | ||
) | ||
|
||
type RunCmd struct { | ||
ProjectDir string `name:"project" short:"p" usage:"plugin project directory" optional:""` | ||
McVersion string `name:"mc" short:"mc" usage:"Minecraft version number target" optional:""` | ||
TemplateJarFile string `name:"jar" short:"t" usage:"template JAR file" optional:""` | ||
} | ||
|
||
func (c *RunCmd) Run() error { | ||
// Root context for the CLI | ||
ctx, cancel := rootContext() | ||
defer cancel() | ||
|
||
// Default to the current working directory | ||
if c.ProjectDir == "" { | ||
c.ProjectDir, _ = os.Getwd() | ||
} | ||
|
||
// Get the Minecraft version | ||
minecraftVersion := mustMinecraftVersion(ctx, c.McVersion) | ||
|
||
// Generate a temp filename for the plugin JAR file | ||
ofile, _ := os.CreateTemp("", "cr-jar-output-*.jar") | ||
ofile.Close() | ||
outputFile := ofile.Name() | ||
defer os.Remove(outputFile) | ||
|
||
// Create the JAR template to build with | ||
var jarTemplate build.JarTemplate | ||
if len(c.TemplateJarFile) > 0 { | ||
jarTemplate = &build.FileJarTemplate{ | ||
Filename: c.TemplateJarFile, | ||
} | ||
} else { | ||
jarTemplate = &build.GitHubJarTemplate{ | ||
MinecraftVersion: minecraftVersion, | ||
} | ||
} | ||
|
||
// Create the project | ||
crProject := project.Project{ | ||
Dir: c.ProjectDir, | ||
} | ||
|
||
// Create the build action | ||
buildAction := build.BuildAction{ | ||
Project: &crProject, | ||
JarTemplate: jarTemplate, | ||
MinecraftVersion: minecraftVersion, | ||
OutputFile: outputFile, | ||
} | ||
|
||
// Run the build action | ||
if err := buildAction.Run(ctx); err != nil { | ||
return err | ||
} | ||
|
||
// Create a fetcher for the Minecraft server JAR file that caches the files locally | ||
serverJarFetcher, err := server.NewCachedFetcher(&server.HttpFetcher{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Create the serve runner | ||
serveAction := serve.ServeAction{ | ||
MinecraftVersion: minecraftVersion, | ||
PluginJarPath: outputFile, | ||
ServerJarFetcher: serverJarFetcher, | ||
} | ||
return serveAction.Run(ctx) | ||
} |
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,14 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/customrealms/cli/pkg/version" | ||
) | ||
|
||
type VersionCmd struct{} | ||
|
||
func (c *VersionCmd) Run() error { | ||
fmt.Printf("@customrealms/cli (crx) v%s\n", version.Version) | ||
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,48 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/customrealms/cli/internal/actions/build" | ||
"github.com/customrealms/cli/internal/project" | ||
) | ||
|
||
type YmlCmd struct { | ||
ProjectDir string `name:"project" short:"p" usage:"plugin project directory" optional:""` | ||
McVersion string `name:"mc" short:"mc" usage:"Minecraft version number target" optional:""` | ||
} | ||
|
||
func (c *YmlCmd) Run() error { | ||
// Root context for the CLI | ||
ctx, cancel := rootContext() | ||
defer cancel() | ||
|
||
// Default to the current working directory | ||
if c.ProjectDir == "" { | ||
c.ProjectDir, _ = os.Getwd() | ||
} | ||
|
||
// Get the Minecraft version | ||
minecraftVersion := mustMinecraftVersion(ctx, c.McVersion) | ||
|
||
// Create the project | ||
crProject := project.Project{ | ||
Dir: c.ProjectDir, | ||
} | ||
|
||
// Read the package.json file | ||
packageJson, err := crProject.PackageJSON() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Define the plugin.yml details for the plugin | ||
pluginYml := &build.PluginYml{ | ||
MinecraftVersion: minecraftVersion, | ||
PackageJSON: packageJson, | ||
} | ||
fmt.Println(pluginYml) | ||
|
||
return nil | ||
} |
Oops, something went wrong.