예제 #1
0
파일: main.go 프로젝트: jemygraw/qlive
func main() {
	args := os.Args
	argc := len(args)

	if argc > 2 {
		cmd := args[1]
		subCmd := args[2]
		if cliFunc, ok := supportedCmds[cmd]; ok {
			cliFunc(subCmd)
		} else {
			fmt.Println("Unknown cmd", fmt.Sprintf("`%s`", cmd))
		}
	} else {
		if argc > 1 {
			//parse flags, show help or version
			option := args[1]
			switch option {
			case "-v":
				cli.Version()
			case "-h":
				cli.Help()
			default:
				fmt.Println("Unknow option", fmt.Sprintf("`%s`", option))
			}
		} else {
			fmt.Println("Use -h to see supported commands.")
		}
	}
}
예제 #2
0
파일: main.go 프로젝트: auqf/qshell
func main() {
	//set cpu count
	runtime.GOMAXPROCS(runtime.NumCPU())
	//set qshell user agent
	rpc.UserAgent = cli.UserAgent()

	//parse command
	args := os.Args
	argc := len(args)
	log.SetOutputLevel(log.Linfo)
	log.SetOutput(os.Stdout)
	if argc > 1 {
		cmd := ""
		params := []string{}
		option := args[1]
		if option == "-d" {
			if argc > 2 {
				cmd = args[2]
				if argc > 3 {
					params = args[3:]
				}
			}
			log.SetOutputLevel(log.Ldebug)
		} else if option == "-v" {
			cli.Version()
			return
		} else if option == "-h" {
			cli.Help("help")
			return
		} else {
			cmd = args[1]
			if argc > 2 {
				params = args[2:]
			}
		}
		if cmd == "" {
			fmt.Println("Error: no subcommand specified")
			return
		}
		hit := false
		for cmdName, cliFunc := range supportedCmds {
			if cmdName == cmd {
				cliFunc(cmd, params...)
				hit = true
				break
			}
		}
		if !hit {
			fmt.Println(fmt.Sprintf("Error: unknown cmd `%s'", cmd))
		}
	} else {
		fmt.Println("Use help or help [cmd1 [cmd2 [cmd3 ...]]] to see supported commands.")
	}
}
예제 #3
0
파일: main.go 프로젝트: jbasttdi/qshell
func main() {
	args := os.Args
	argc := len(args)
	log.SetOutputLevel(log.Linfo)
	if argc > 1 {
		cmd := ""
		params := []string{}
		option := args[1]
		if option == "-d" {
			if argc > 2 {
				cmd = args[2]
				if argc > 3 {
					params = args[3:]
				}
			}
			log.SetOutputLevel(log.Ldebug)
		} else if option == "-v" {
			cli.Version()
			return
		} else if option == "-h" {
			cli.Help("help")
			return
		} else {
			cmd = args[1]
			if argc > 2 {
				params = args[2:]
			}
		}
		if cmd == "" {
			fmt.Println("Error: no subcommand specified")
			return
		}
		hit := false
		for cmdName, cliFunc := range supportedCmds {
			if cmdName == cmd {
				cliFunc(cmd, params...)
				hit = true
				break
			}
		}
		if !hit {
			fmt.Println(fmt.Sprintf("Error: unknow cmd `%s'", cmd))
		}
	} else {
		fmt.Println("Use help or help [cmd1 [cmd2 [cmd3 ...]]] to see supported commands.")
	}
}
예제 #4
0
파일: main.go 프로젝트: yuanpm/qshell
func main() {
	//set cpu count
	runtime.GOMAXPROCS(runtime.NumCPU())
	//set qshell user agent
	rpc.UserAgent = cli.UserAgent()

	//parse command
	log.SetOutputLevel(log.Linfo)
	log.SetOutput(os.Stdout)

	if len(os.Args) <= 1 {
		fmt.Println("Use help or help [cmd1 [cmd2 [cmd3 ...]]] to see supported commands.")
		return
	}

	//flag
	var debugMode bool
	var forceMode bool
	var helpMode bool
	var versionMode bool

	flag.BoolVar(&debugMode, "d", false, "debug mode")
	flag.BoolVar(&forceMode, "f", false, "force mode")
	flag.BoolVar(&helpMode, "h", false, "show help")
	flag.BoolVar(&versionMode, "v", false, "show version")

	flag.Parse()

	if helpMode {
		cli.Help("help")
		return
	}

	if versionMode {
		cli.Version()
		return
	}

	if debugMode {
		log.SetOutputLevel(log.Ldebug)
	}

	if forceMode {
		cli.ForceMode = true
	}

	args := flag.Args()

	cmd := args[0]
	params := args[1:]

	if cmd == "" {
		fmt.Println("Error: no subcommand specified")
		return
	}

	if cliFunc, ok := supportedCmds[cmd]; ok {
		cliFunc(cmd, params...)
	} else {
		fmt.Println(fmt.Sprintf("Error: unknown cmd `%s`", cmd))
	}

}