4 Commits
v0.6.0 ... main

Author SHA1 Message Date
04e18514a5 [noci] README update
All checks were successful
code scans / scans (push) Successful in 36s
2025-11-27 09:58:39 -05:00
479204cb42 adding subcommand aliases
All checks were successful
code scans / scans (push) Successful in 20s
2025-11-26 13:13:00 -05:00
64a0f7422a Merge pull request 'moving run command' (#11) from chore/cmd-structure-update into main
All checks were successful
code scans / scans (push) Successful in 20s
Reviewed-on: #11
2025-11-26 18:05:50 +00:00
b41b5e2be8 moving run command
All checks were successful
code scans / scans (push) Successful in 26s
code scans / scans (pull_request) Successful in 24s
- run command is no longer attached to the 'command' subcmd
- run is standalone
2025-11-26 13:04:14 -05:00
13 changed files with 36 additions and 23 deletions

View File

@@ -82,7 +82,7 @@ Command: kill %s
``` ```
```bash ```bash
#runs the 'kill' command on 'player' #runs the 'kill' command on 'player'
mctl command run placeholder player mctl run placeholder player
``` ```
Running the placeholder command with the arg 'player' will run 'kill player' on the server Running the placeholder command with the arg 'player' will run 'kill player' on the server

View File

@@ -8,12 +8,14 @@ import (
"fmt" "fmt"
"os" "os"
"code.jakeyoungdev.com/jake/mctl/constants"
"code.jakeyoungdev.com/jake/mctl/database" "code.jakeyoungdev.com/jake/mctl/database"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var addCmd = &cobra.Command{ var addCmd = &cobra.Command{
Use: "add", Use: "add",
Aliases: []string{"a"},
Example: "mctl command add", Example: "mctl command add",
Short: "Saves a new command to the database", Short: "Saves a new command to the database",
SilenceUsage: true, SilenceUsage: true,
@@ -42,8 +44,8 @@ var addCmd = &cobra.Command{
err = db.SaveCmd(cfgname, cfgcmd) err = db.SaveCmd(cfgname, cfgcmd)
if err != nil { if err != nil {
if err.Error() == ErrInit { if err.Error() == constants.ErrInit {
fmt.Println(ErrInitRsp) fmt.Println(constants.ErrInitRsp)
return return
} }
} }

View File

@@ -7,16 +7,10 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
const (
//sqlite doesn't have an error type for this error, but we want to catch when this error is thrown
//and provide the proper response. It should not be treated as an error if the db isn't setup.
ErrInit = "sqlite3: SQL logic error: no such table: commands"
ErrInitRsp = "The 'init' command must be run before mctl can be used"
)
// CommandCmd is such a cool name lol // CommandCmd is such a cool name lol
var CommandCmd = &cobra.Command{ var CommandCmd = &cobra.Command{
Use: "command", Use: "command",
Aliases: []string{"c"},
Example: "mctl command <subcommand>", Example: "mctl command <subcommand>",
} }

View File

@@ -7,6 +7,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"code.jakeyoungdev.com/jake/mctl/constants"
"code.jakeyoungdev.com/jake/mctl/database" "code.jakeyoungdev.com/jake/mctl/database"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@@ -23,8 +24,8 @@ var deleteCmd = &cobra.Command{
err = db.DeleteCmd(args[0]) err = db.DeleteCmd(args[0])
if err != nil { if err != nil {
if err.Error() == ErrInit { if err.Error() == constants.ErrInit {
fmt.Println(ErrInitRsp) fmt.Println(constants.ErrInitRsp)
return return
} }
} }

View File

@@ -6,12 +6,14 @@ package command
import ( import (
"fmt" "fmt"
"code.jakeyoungdev.com/jake/mctl/constants"
"code.jakeyoungdev.com/jake/mctl/database" "code.jakeyoungdev.com/jake/mctl/database"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var viewCmd = &cobra.Command{ var viewCmd = &cobra.Command{
Use: "view", Use: "view",
Aliases: []string{"v"},
Example: "mctl command view", Example: "mctl command view",
Short: "view all saved commands", Short: "view all saved commands",
SilenceUsage: true, SilenceUsage: true,
@@ -22,8 +24,8 @@ var viewCmd = &cobra.Command{
ts, err := db.AllCmds() ts, err := db.AllCmds()
if err != nil { if err != nil {
if err.Error() == ErrInit { if err.Error() == constants.ErrInit {
fmt.Println(ErrInitRsp) fmt.Println(constants.ErrInitRsp)
return return
} }
} }

View File

@@ -9,7 +9,7 @@ import (
"os" "os"
"strings" "strings"
"code.jakeyoungdev.com/jake/mctl/cmd/command" "code.jakeyoungdev.com/jake/mctl/constants"
"code.jakeyoungdev.com/jake/mctl/database" "code.jakeyoungdev.com/jake/mctl/database"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@@ -32,8 +32,8 @@ var destroyCmd = &cobra.Command{
err = db.Destroy() err = db.Destroy()
if err != nil { if err != nil {
if err.Error() == command.ErrInit { if err.Error() == constants.ErrInit {
fmt.Println(command.ErrInitRsp) fmt.Println(constants.ErrInitRsp)
return return
} }
} }

View File

@@ -16,7 +16,7 @@ var rootCmd = &cobra.Command{
Use: "mctl", Use: "mctl",
Short: "A remote console client", Short: "A remote console client",
Long: `mctl is a terminal-friendly remote console client made to manage game servers.`, Long: `mctl is a terminal-friendly remote console client made to manage game servers.`,
Version: "v0.5.1", Version: "v0.7.1",
} }
// Execute adds all child commands to the root command and sets flags appropriately. // Execute adds all child commands to the root command and sets flags appropriately.

View File

@@ -1,7 +1,7 @@
/* /*
Copyright © 2025 Jake jake.young.dev@gmail.com Copyright © 2025 Jake jake.young.dev@gmail.com
*/ */
package command package cmd
import ( import (
"errors" "errors"
@@ -9,6 +9,7 @@ import (
"strings" "strings"
"code.jakeyoungdev.com/jake/mctl/client" "code.jakeyoungdev.com/jake/mctl/client"
"code.jakeyoungdev.com/jake/mctl/constants"
"code.jakeyoungdev.com/jake/mctl/database" "code.jakeyoungdev.com/jake/mctl/database"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@@ -19,7 +20,8 @@ var (
var runCmd = &cobra.Command{ var runCmd = &cobra.Command{
Use: "run", Use: "run",
Example: "mctl command run -s <server> <command> args...", Aliases: []string{"r"},
Example: "mctl run -s <server> <command> args...",
Short: "Runs a saved command on a server", Short: "Runs a saved command on a server",
Long: `Runs the named command with the provided args on the default/active server unless -s is specified`, Long: `Runs the named command with the provided args on the default/active server unless -s is specified`,
SilenceUsage: true, SilenceUsage: true,
@@ -34,8 +36,8 @@ var runCmd = &cobra.Command{
crun, err := db.Cmd(cname) crun, err := db.Cmd(cname)
if err != nil { if err != nil {
if err.Error() == ErrInit { if err.Error() == constants.ErrInit {
fmt.Println(ErrInitRsp) fmt.Println(constants.ErrInitRsp)
return nil return nil
} }
return err return err
@@ -76,5 +78,5 @@ var runCmd = &cobra.Command{
func init() { func init() {
runCmd.Flags().StringVarP(&cfgserver, "server", "s", "", "server name") runCmd.Flags().StringVarP(&cfgserver, "server", "s", "", "server name")
CommandCmd.AddCommand(runCmd) rootCmd.AddCommand(runCmd)
} }

View File

@@ -18,6 +18,7 @@ import (
var addCmd = &cobra.Command{ var addCmd = &cobra.Command{
Use: "add", Use: "add",
Aliases: []string{"a"},
Example: "mctl server add", Example: "mctl server add",
Short: "Saves a new server configuration", Short: "Saves a new server configuration",
Long: `Saves server address, alias, port, and password to the database.`, Long: `Saves server address, alias, port, and password to the database.`,

View File

@@ -16,6 +16,7 @@ const (
var ServerCmd = &cobra.Command{ var ServerCmd = &cobra.Command{
Use: "server", Use: "server",
Aliases: []string{"s"},
Example: "mctl server <subcommand>", Example: "mctl server <subcommand>",
} }

View File

@@ -16,6 +16,7 @@ import (
var updateCmd = &cobra.Command{ var updateCmd = &cobra.Command{
Use: "update", Use: "update",
Aliases: []string{"u"},
Example: "mctl server update <name>", Example: "mctl server update <name>",
Short: "updates a saved servers password in the database", Short: "updates a saved servers password in the database",
SilenceUsage: true, SilenceUsage: true,

View File

@@ -15,6 +15,7 @@ var decode bool
var viewCmd = &cobra.Command{ var viewCmd = &cobra.Command{
Use: "view", Use: "view",
Aliases: []string{"v"},
Example: "mctl server view", Example: "mctl server view",
Short: "view all saved servers", Short: "view all saved servers",
SilenceUsage: true, SilenceUsage: true,

8
constants/error.go Normal file
View File

@@ -0,0 +1,8 @@
package constants
const (
//sqlite doesn't have an error type for this error, but we want to catch when this error is thrown
//and provide the proper response. It should not be treated as an error if the db isn't setup.
ErrInit = "sqlite3: SQL logic error: no such table: commands"
ErrInitRsp = "The 'init' command must be run before mctl can be used"
)