If no argument is provided default to .

This commit is contained in:
2026-06-24 14:19:00 -04:00
parent 1e63040f92
commit bee4ed305e
6 changed files with 31 additions and 11 deletions

10
main.go
View File

@@ -29,28 +29,28 @@ var startCmd = &cobra.Command{
Use: "start", Use: "start",
Short: "Start the minecraft server", Short: "Start the minecraft server",
Run: server.Start, Run: server.Start,
Args: cobra.ExactArgs(1), Args: cobra.MaximumNArgs(1),
} }
var stopCmd = &cobra.Command{ var stopCmd = &cobra.Command{
Use: "stop", Use: "stop",
Short: "Stop the minecraft server", Short: "Stop the minecraft server",
Run: server.Stop, Run: server.Stop,
Args: cobra.ExactArgs(1), Args: cobra.MaximumNArgs(1),
} }
var restartCmd = &cobra.Command{ var restartCmd = &cobra.Command{
Use: "restart", Use: "restart",
Short: "Restart the minecraft server", Short: "Restart the minecraft server",
Run: server.Restart, Run: server.Restart,
Args: cobra.ExactArgs(1), Args: cobra.MaximumNArgs(1),
} }
var shellCmd = &cobra.Command{ var shellCmd = &cobra.Command{
Use: "shell", Use: "shell",
Short: "Access RCON shell", Short: "Access RCON shell",
Run: server.Shell, Run: server.Shell,
Args: cobra.ExactArgs(1), Args: cobra.MaximumNArgs(1),
} }
var sayCmd = &cobra.Command{ var sayCmd = &cobra.Command{
@@ -64,7 +64,7 @@ var statusCmd = &cobra.Command{
Use: "status", Use: "status",
Short: "Get the status of the server", Short: "Get the status of the server",
Run: server.Status, Run: server.Status,
Args: cobra.MinimumNArgs(1), Args: cobra.MaximumNArgs(1),
} }
//go:embed templates/docker-compose.yml //go:embed templates/docker-compose.yml

View File

@@ -9,7 +9,10 @@ import (
) )
func Restart(cmd *cobra.Command, args []string) { func Restart(cmd *cobra.Command, args []string) {
dir := args[0] dir := "."
if len(args) > 0 {
dir = args[0]
}
if err := os.Chdir(dir); err != nil { if err := os.Chdir(dir); err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@@ -9,7 +9,10 @@ import (
) )
func Shell(cmd *cobra.Command, args []string) { func Shell(cmd *cobra.Command, args []string) {
dir := args[0] dir := "."
if len(args) > 0 {
dir = args[0]
}
name := getServerName(dir) name := getServerName(dir)
@@ -20,7 +23,10 @@ func Shell(cmd *cobra.Command, args []string) {
} }
func Say(cmd *cobra.Command, args []string) { func Say(cmd *cobra.Command, args []string) {
dir := args[0] dir := "."
if len(args) > 0 {
dir = args[0]
}
name := getServerName(dir) name := getServerName(dir)

View File

@@ -9,7 +9,11 @@ import (
) )
func Start(cmd *cobra.Command, args []string) { func Start(cmd *cobra.Command, args []string) {
dir := args[0] dir := "."
if len(args) > 0 {
dir = args[0]
}
if err := os.Chdir(dir); err != nil { if err := os.Chdir(dir); err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@@ -9,7 +9,10 @@ import (
) )
func Status(cmd *cobra.Command, args []string) { func Status(cmd *cobra.Command, args []string) {
dir := args[0] dir := "."
if len(args) > 0 {
dir = args[0]
}
name := getServerName(dir) name := getServerName(dir)

View File

@@ -9,7 +9,11 @@ import (
) )
func Stop(cmd *cobra.Command, args []string) { func Stop(cmd *cobra.Command, args []string) {
dir := args[0] dir := "."
if len(args) > 0 {
dir = args[0]
}
if err := os.Chdir(dir); err != nil { if err := os.Chdir(dir); err != nil {
log.Fatal(err) log.Fatal(err)
} }