package main import ( "flag" "fmt" "os" "strings" ) var isNode bool var isHost bool var isRpc bool var configPath string var rpcPath string func main() { // first, we need to determine who we are: node, host or rpc. // determine by executable name (lux binary will be symlinked to lux-node, lux-host, luc-rpc), // or by explicit cli flag (--node, --host, --rpc) flag.BoolVar(&isNode, "node", false, "LUX node") flag.BoolVar(&isHost, "host", false, "LUX host") flag.BoolVar(&isRpc, "rpc", false, "RPC tool") flag.StringVar(&configPath, "config", "", "node or host config") flag.StringVar(&rpcPath, "rpc-path", "", "path to RPC UNIX socket or TCP socket, must be in unix:// or tcp:// form") flag.Parse() if !isNode && !isHost && !isRpc { // determine by argv[0] if strings.Contains(os.Args[0], "node") { isNode = true } else if strings.Contains(os.Args[0], "host") { isHost = true } else if strings.Contains(os.Args[0], "rpc") { isRpc = true } } if (isNode || isHost) && configPath == "" { fmt.Fprintln(os.Stderr, "must provide config path") os.Exit(1) } else if isRpc && rpcPath == "" { fmt.Fprintln(os.Stderr, "must provide RPC socket path") os.Exit(1) } }