lots o progress
- added 'command' subcommand - removed viper - setup commands added - still a WIP - readme TODO update
This commit is contained in:
50
cmd/command/add.go
Normal file
50
cmd/command/add.go
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
Copyright © 2025 Jake jake.young.dev@gmail.com
|
||||
*/
|
||||
package command
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"code.jakeyoungdev.com/jake/mctl/database"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var addCmd = &cobra.Command{
|
||||
Use: "add",
|
||||
Example: "mctl command add",
|
||||
// Short: "Saves a new server configuration",
|
||||
// Long: `Saves server address, alias, port, and password.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
|
||||
//get server information
|
||||
var cfgname string
|
||||
fmt.Printf("Command alias: ")
|
||||
if scanner.Scan() {
|
||||
cfgname = scanner.Text()
|
||||
}
|
||||
|
||||
var cfgcmd string
|
||||
fmt.Printf("Command: ")
|
||||
if scanner.Scan() {
|
||||
cfgcmd = scanner.Text()
|
||||
}
|
||||
|
||||
db, err := database.New()
|
||||
cobra.CheckErr(err)
|
||||
defer db.Close()
|
||||
|
||||
err = db.Init()
|
||||
cobra.CheckErr(err)
|
||||
|
||||
err = db.SaveCmd(cfgname, cfgcmd)
|
||||
cobra.CheckErr(err)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
CommandCmd.AddCommand(addCmd)
|
||||
}
|
22
cmd/command/command.go
Normal file
22
cmd/command/command.go
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
Copyright © 2025 Jake jake.young.dev@gmail.com
|
||||
*/
|
||||
package command
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// CommandCmd is such a cool name lol
|
||||
var CommandCmd = &cobra.Command{
|
||||
Use: "command",
|
||||
Example: "mctl command <subcommand>",
|
||||
// Short: "A remote console client",
|
||||
// Long: `mctl is a terminal-friendly remote console client made to manage game servers.`,
|
||||
// Version: "v0.3.4",
|
||||
// Run: func(cmd *cobra.Command, args []string) { },
|
||||
}
|
||||
|
||||
func init() {
|
||||
// rootCmd.AddCommand()
|
||||
}
|
39
cmd/command/delete.go
Normal file
39
cmd/command/delete.go
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright © 2025 Jake jake.young.dev@gmail.com
|
||||
*/
|
||||
package command
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"code.jakeyoungdev.com/jake/mctl/database"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var deleteCmd = &cobra.Command{
|
||||
Use: "delete",
|
||||
Example: "mctl command delete <name>",
|
||||
// Short: "Deletes a server",
|
||||
// Long: `Deletes server configuration`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
db, err := database.New()
|
||||
cobra.CheckErr(err)
|
||||
defer db.Close()
|
||||
|
||||
err = db.DeleteCmd(args[0])
|
||||
cobra.CheckErr(err)
|
||||
|
||||
fmt.Println("Command deleted!")
|
||||
},
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 {
|
||||
return errors.New("name parameter missing")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
CommandCmd.AddCommand(deleteCmd)
|
||||
}
|
35
cmd/command/view.go
Normal file
35
cmd/command/view.go
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright © 2025 Jake jake.young.dev@gmail.com
|
||||
*/
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.jakeyoungdev.com/jake/mctl/database"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var viewCmd = &cobra.Command{
|
||||
Use: "view",
|
||||
Example: "mctl command view",
|
||||
// Short: "view all commands",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
db, err := database.New()
|
||||
cobra.CheckErr(err)
|
||||
defer db.Close()
|
||||
|
||||
ts, err := db.GetAllCmds()
|
||||
cobra.CheckErr(err)
|
||||
|
||||
for _, s := range ts {
|
||||
fmt.Println("-----")
|
||||
fmt.Printf("Name: %s\n", s.Name)
|
||||
fmt.Printf("Command: %s\n", s.Command)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
CommandCmd.AddCommand(viewCmd)
|
||||
}
|
Reference in New Issue
Block a user