Recovered the original repl command
This commit is contained in:
+92
-93
@@ -1,104 +1,103 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"esdi/tui"
|
||||
"esdi/peripheral"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
repl "github.com/ESilva15/ESgoRepl"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// func replCmdAction(cmd *cobra.Command, args []string) {
|
||||
// r := repl.NewREPL(repl.REPLCfg{
|
||||
// PS1: "\rESDI > ",
|
||||
// })
|
||||
//
|
||||
// perClerk := peripheral.NewPeripheralDeviceClerk()
|
||||
//
|
||||
// discoverDevicesREPLCmd := repl.Command{
|
||||
// Name: "discover",
|
||||
// Usage: "discovers connected devices",
|
||||
// Action: func(r *repl.REPL, args []string) error {
|
||||
// err := perClerk.FindDevices()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// listDevicesREPLCmd := repl.Command{
|
||||
// Name: "list",
|
||||
// Usage: "lists connected devices",
|
||||
// Action: func(r *repl.REPL, args []string) error {
|
||||
// _ = perClerk.ListDevices()
|
||||
//
|
||||
// return nil
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// listDeviceAPIREPLCmd := repl.Command{
|
||||
// Name: "v-api",
|
||||
// Usage: "shows API of a device - pass its ID",
|
||||
// Action: func(r *repl.REPL, args []string) error {
|
||||
// // We should add this to the REPL instead
|
||||
// if len(args) < 1 {
|
||||
// return fmt.Errorf("requires at least on argument")
|
||||
// }
|
||||
//
|
||||
// // First and only argument should be the ID of the device we want to use
|
||||
// targetID, err := strconv.ParseInt(args[0], 10, 0)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// err = perClerk.ListDeviceAPI(uint8(targetID))
|
||||
// if err != nil {
|
||||
// fmt.Println("failed to view device API: ", err.Error())
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// runDeviceAPIREPLCmd := repl.Command{
|
||||
// Name: "v-run",
|
||||
// Usage: "runs a funcion of a device - pass its ID and function name",
|
||||
// Action: func(r *repl.REPL, args []string) error {
|
||||
// // We should add this to the REPL instead
|
||||
// if len(args) < 3 {
|
||||
// return fmt.Errorf("requires at least on argument")
|
||||
// }
|
||||
//
|
||||
// // First and only argument should be the ID of the device we want to use
|
||||
// targetID, err := strconv.ParseInt(args[0], 10, 0)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// fnName := args[1]
|
||||
// fnArgs := args[2:]
|
||||
//
|
||||
// err = perClerk.RunDeviceFunction(uint8(targetID), fnName, fnArgs)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// r.RegisterCMD(discoverDevicesREPLCmd)
|
||||
// r.RegisterCMD(listDevicesREPLCmd)
|
||||
// r.RegisterCMD(listDeviceAPIREPLCmd)
|
||||
// r.RegisterCMD(runDeviceAPIREPLCmd)
|
||||
//
|
||||
// r.Start()
|
||||
// r.Close()
|
||||
// }
|
||||
|
||||
func replCmdAction(cmd *cobra.Command, args []string) {
|
||||
// repl.Run()
|
||||
tui.Run()
|
||||
r := repl.NewREPL(repl.REPLCfg{
|
||||
PS1: "\rESDI > ",
|
||||
})
|
||||
|
||||
perClerk := peripheral.NewPeripheralDeviceClerk()
|
||||
|
||||
discoverDevicesREPLCmd := repl.Command{
|
||||
Name: "discover",
|
||||
Usage: "discovers connected devices",
|
||||
Action: func(r *repl.REPL, args []string) error {
|
||||
err := perClerk.FindDevices()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
listDevicesREPLCmd := repl.Command{
|
||||
Name: "list",
|
||||
Usage: "lists connected devices",
|
||||
Action: func(r *repl.REPL, args []string) error {
|
||||
_ = perClerk.ListDevices()
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
listDeviceAPIREPLCmd := repl.Command{
|
||||
Name: "v-api",
|
||||
Usage: "shows API of a device - pass its ID",
|
||||
Action: func(r *repl.REPL, args []string) error {
|
||||
// We should add this to the REPL instead
|
||||
if len(args) < 1 {
|
||||
return fmt.Errorf("requires at least on argument")
|
||||
}
|
||||
|
||||
// First and only argument should be the ID of the device we want to use
|
||||
targetID, err := strconv.ParseInt(args[0], 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = perClerk.ListDeviceAPI(uint8(targetID))
|
||||
if err != nil {
|
||||
fmt.Println("failed to view device API: ", err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
runDeviceAPIREPLCmd := repl.Command{
|
||||
Name: "v-run",
|
||||
Usage: "runs a funcion of a device - pass its ID and function name",
|
||||
Action: func(r *repl.REPL, args []string) error {
|
||||
// We should add this to the REPL instead
|
||||
if len(args) < 3 {
|
||||
return fmt.Errorf("requires at least on argument")
|
||||
}
|
||||
|
||||
// First and only argument should be the ID of the device we want to use
|
||||
targetID, err := strconv.ParseInt(args[0], 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fnName := args[1]
|
||||
fnArgs := args[2:]
|
||||
|
||||
err = perClerk.RunDeviceFunction(uint8(targetID), fnName, fnArgs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
r.RegisterCMD(discoverDevicesREPLCmd)
|
||||
r.RegisterCMD(listDevicesREPLCmd)
|
||||
r.RegisterCMD(listDeviceAPIREPLCmd)
|
||||
r.RegisterCMD(runDeviceAPIREPLCmd)
|
||||
|
||||
r.Start()
|
||||
r.Close()
|
||||
}
|
||||
|
||||
// removeLabelCmd represents the removeLabel command
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"esdi/tui"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func tuiCmdAction(cmd *cobra.Command, args []string) {
|
||||
err := tui.Run()
|
||||
if err != nil {
|
||||
fmt.Printf("Error running TUI: %s\n", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// removeLabelCmd represents the removeLabel command
|
||||
var tuiCmd = &cobra.Command{
|
||||
Use: "tui",
|
||||
Short: "runs a TUI",
|
||||
Long: ``,
|
||||
Run: tuiCmdAction,
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(tuiCmd)
|
||||
}
|
||||
@@ -3,6 +3,7 @@ module esdi
|
||||
go 1.25.5
|
||||
|
||||
require (
|
||||
github.com/ESilva15/ESgoRepl v0.1.0
|
||||
github.com/ESilva15/gobngsdk v0.0.2
|
||||
github.com/ESilva15/goirsdk v0.2.0
|
||||
github.com/charmbracelet/bubbletea v1.3.10
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
github.com/ESilva15/ESgoRepl v0.1.0 h1:hOVcRBfdP8Yw1kLr2tFoM3SetV7vxFswKjzfAtq8UgM=
|
||||
github.com/ESilva15/ESgoRepl v0.1.0/go.mod h1:O2JQMyEgHy0zf9UvzvLNvp2w95T2uazc3torrzRmG9Y=
|
||||
github.com/ESilva15/gobngsdk v0.0.2 h1:N6stNOE14Wg80BAZMFu/Qd9Qa/J0DmExCfdPoDf7lco=
|
||||
github.com/ESilva15/gobngsdk v0.0.2/go.mod h1:cKLaZRgM0tGGXDvosaSjHnxeyC5Y6rg7zCLqEUJnOzw=
|
||||
github.com/ESilva15/goirsdk v0.2.0 h1:zmtYyH3ayGRcDfzzLrJmEpX6zdmCHTUqbs4tnV2hXmI=
|
||||
|
||||
Reference in New Issue
Block a user