starting sqlite rewrite
- adding db connector - starting rewrite of commands - WIP
This commit is contained in:
15
cmd/run.go
15
cmd/run.go
@@ -4,11 +4,13 @@ Copyright © 2025 Jake jake.young.dev@gmail.com
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"code.jakeyoungdev.com/jake/mctl/client"
|
||||
"code.jakeyoungdev.com/jake/mctl/database"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
@@ -22,13 +24,16 @@ var runCmd = &cobra.Command{
|
||||
Long: `Loads a saved command, injects the supplied arguments into the command, and sends the command to the remove server
|
||||
printing the response`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cm := viper.Get("customcmd").(map[string]any)
|
||||
//is this an existing command
|
||||
cmdRun, ok := cm[args[0]]
|
||||
if !ok {
|
||||
db, err := database.New()
|
||||
cobra.CheckErr(err)
|
||||
defer db.Close()
|
||||
|
||||
sc, err := db.GetCmd(args[0])
|
||||
if err == sql.ErrNoRows {
|
||||
fmt.Printf("command %s not found", args[0])
|
||||
return
|
||||
}
|
||||
cobra.CheckErr(err)
|
||||
|
||||
//convert arguments to interface
|
||||
var nargs []any
|
||||
@@ -37,7 +42,7 @@ var runCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
//inject arguments
|
||||
fixed := fmt.Sprintf(cmdRun.(string), nargs...)
|
||||
fixed := fmt.Sprintf(sc, nargs...)
|
||||
fmt.Printf("Running saved command %s\n", fixed)
|
||||
|
||||
//create client and send command
|
||||
|
||||
Reference in New Issue
Block a user