Ejemplo n.º 1
0
// 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)
	}
}
Ejemplo n.º 2
0
Archivo: main.go Proyecto: 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)
	}

}
Ejemplo n.º 3
0
Archivo: main.go Proyecto: 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)
	}
}
Ejemplo n.º 4
0
Archivo: main.go Proyecto: 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)
	}

}