示例#1
0
文件: main.go 项目: jamesbjackson/kh
// This doesn't use a cli argument parser because such libraries typically cannot
// handle subcommands that are dynamically loaded
// For this reason cli parsing is done manually
func main() {
	args := parseFlagsAndArgs()
	h := makeHand()
	if fingerInvoked(h, os.Args) {
		fingerName := os.Args[1]
		remainingArgs := findFingerArgs(os.Args)
		flags := map[string]bool{"help": helpFlag, "verbose": verboseFlag}
		if err := h.ExecuteFinger(fingerName, flags, remainingArgs); err != nil {
			log.Errorf("Encountered error executing finger %s", fingerName)
			log.Errorf("Error message: %v", err)
			os.Exit(1)
		}
		os.Exit(0)
	}
	cmd := args[1]
	log.Debug(cmd)
	switch cmd {
	case "version":
		showVersion()
	case "help":
		showHelp(h)
	case "update":
		executeUpdate(h, kh.StripFlags(os.Args[2:]))
	case "":
		showHelp(h)
	}
}
示例#2
0
文件: main.go 项目: bryanwb/kh
func executeFinger(h *kh.Hand, fingerName string) {
	remainingArgs := findFingerArgs(os.Args)
	flags := map[string]bool{"help": helpFlag, "verbose": verboseFlag}
	if err := h.ExecuteFinger(fingerName, flags, kh.StripFlags(remainingArgs)); err != nil {
		log.Errorf("Encountered error executing finger %s", fingerName)
		log.Errorf("Error message: %v", err)
		os.Exit(1)
	}

}
示例#3
0
文件: main.go 项目: bryanwb/kh
func doInstall(h *kh.Hand, args []string) {
	args = kh.StripFlags(args)
	if kh.EmptyArgs(args) {
		log.Error("You must specify one or more fingers to install")
		os.Exit(1)
	}
	if err := h.InstallFingers(args); err != nil {
		log.Error(err.Error())
		os.Exit(1)
	}
}
示例#4
0
文件: main.go 项目: bryanwb/kh
// This doesn't use a cli argument parser because such libraries typically cannot
// handle subcommands that are dynamically loaded
// For this reason cli parsing is done manually
func main() {
	args, parseErr := parseFlagsAndArgs()
	h, _ := makeHand()
	if fingerInvoked(h, args[0]) {
		executeFinger(h, args[0])
		os.Exit(0)
	}
	cmd := args[0]
	// since not executing our finger, throw an error
	// if we see unknown flags
	if parseErr != nil {
		// flush any parsing errors encountered
		// while parsing command line earlier
		fmt.Fprint(os.Stderr, flagParsingOut.String())
		flag.Usage()
		os.Exit(1)
	}
	switch cmd {
	case "version":
		showVersion()
	case "help":
		showHelp(h)
	case "update":
		executeUpdate(h, kh.StripFlags(os.Args[2:]))
	case "init":
		doInit()
	case "install":
		doInstall(h, os.Args[2:])
	case "":
		showHelp(h)
	case "list":
		showList(h)
	default:
		fmt.Printf("Unknown finger or subcommand \"%s\"\nType `kh list` to see available fingers\n", cmd)
	}

}