basic test of pure cmd line app

This commit is contained in:
2020-06-10 17:39:36 +02:00
parent d04ebe281a
commit b887190c80
4 changed files with 175 additions and 2 deletions

41
main.go Normal file
View File

@@ -0,0 +1,41 @@
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var modbusreadCmd = &cobra.Command{
Use: "modbusread",
Short: "Reads data from a modbus device using TCP/IP or UDP",
Long: `Reads data from a modbus device using TCP or UDP.
It expects following arguments:
modbusread <host-or-ip> <unitid> <startreg> [<endreg>]
`,
Args: cobra.ExactArgs(1),
Run: run,
}
func run(cmd *cobra.Command, args []string) {
// Get managed repos from environment variables
// root := os.Getenv("MG_ROOT")
/* if root[len(root)-1] != '/' {
root += "/"
} */
fmt.Println(args)
}
func main() {
argsWithProg := os.Args
argsWithoutProg := os.Args[1:]
arg := os.Args[3]
fmt.Println(argsWithProg)
fmt.Println(argsWithoutProg)
fmt.Println(arg)
}