basic test of pure cmd line app
This commit is contained in:
41
main.go
Normal file
41
main.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user