Documentation
¶
Overview ¶
cmd pkg handles cobra api for command line tool
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var RootCmd = &cobra.Command{ Use: "vd", Args: cobra.ExactArgs(1), Version: longVersion, Short: "vd is a easy to use device simulator", Long: `Virtual Device is an open source program that can be used to simulate lab device communication streams. It is useful for testing and debugging software that communicates with lab devices, as well as for creating virtual lab environments for education and research. To run simulator create .toml file with device description and run it using following commands: vd vdfile.toml vd vdfile.toml --listenAddr 127.0.0.1:6666 By default, vd is listenning on 127.0.0.1:9999.`, Run: func(cmd *cobra.Command, args []string) { fmt.Printf(banner, version, website) vdfile, err := vdfile.ReadVDFile(args[0]) if err != nil { fmt.Printf("Config loading failed %v", err) os.Exit(1) } ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) defer stop() str, err := device.NewDevice(vdfile) if err != nil { fmt.Printf("Device creation failed %v", err) os.Exit(1) } ip := viper.GetString("listenAddr") if !verifyIPAddr(ip) { fmt.Println("Wrong TCP address") os.Exit(1) } srv, err := server.New(str, ip) if err != nil { fmt.Printf("TCP server creation failed %v", err) os.Exit(1) } go srv.Start() fmt.Println("vd running on ", gchalk.BrightYellow(ip)) addr := viper.GetString("httpListenAddr") if !verifyIPAddr(addr) { fmt.Println("Wrong HTTP address") os.Exit(1) } a := api.NewHttpApiServer(str) go func() { err = a.Serve(ctx, addr) if err != nil { fmt.Printf("HTTP server failed %v", err) os.Exit(1) } }() <-ctx.Done() srv.Stop() fmt.Println("vd stopped") }, }
rootCmd represents the base command when called without any subcommands
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.