37 lines
722 B
Go
37 lines
722 B
Go
package cmd
|
|
|
|
import (
|
|
"log"
|
|
"net"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
ip net.IP
|
|
port uint16
|
|
proto string
|
|
v6 bool
|
|
)
|
|
|
|
var rootCmd = &cobra.Command{
|
|
Use: "protohacking",
|
|
Short: "Protohackers challenge servers",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
cmd.Help()
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
pflags := rootCmd.PersistentFlags()
|
|
pflags.Uint16VarP(&port, "port", "p", 8088, "Port to TCP listen on")
|
|
pflags.IPVarP(&ip, "ip", "i", net.IPv6unspecified, "Address to listen on")
|
|
pflags.BoolVarP(&v6, "v6", "6", true, "Whether to use IPv6")
|
|
pflags.StringVar(&proto, "proto", "tcp", "Either tcp or udp")
|
|
}
|
|
|
|
func Execute() {
|
|
if err := rootCmd.Execute(); err != nil {
|
|
log.Fatal("fatal error", "err", err)
|
|
}
|
|
}
|