func CreateCLI(commands ...Command) (func(in string), func(in prompt.Document) []prompt.Suggest) {

	var commandList Commands = commands

	// iterates through each registered command until it
	// finds a match and runs its Executor
	executor := func(in string) {
		in = strings.TrimSpace(in)
		args := strings.Split(in, " ")
		command, err := commandList.Match(args[0])

		if err == nil {
			err := command.Executor(args)
			if err != nil {
				fmt.Printf("Error with previous command: %s\n", err)
			}
			return
		}

		switch args[0] {
		case "":
		case "help":
			commandList.GenerateHelp("Available commands:")
		case "exit":
			os.Exit(0)
		default:
			fmt.Println("Sorry, I don't understand.")
		}
	}

	// iterates through each registered command until it
	// finds a match and runs its Completer
	completer := func(in prompt.Document) []prompt.Suggest {
		currentCommand := in.TextBeforeCursor()
		args := strings.Split(currentCommand, " ")
		match, err := commandList.Match(args[0])
		if err != nil {
			suggestions := commandList.GenerateSuggestions()
			return prompt.FilterHasPrefix(suggestions, in.GetWordBeforeCursor(), true)
		}
		if match.Completer != nil {
			return match.Completer(in)
		}

		return []prompt.Suggest{}
	}

	return executor, completer
}
// CreateCLI when provided a list of commands, generates a
// Completer and Executor to run those commands
CreateCLI when provided a list of commands, generates a
Completer and Executor to run those commands
// CreateCLI when provided a list of commands generates a // Completer and Executor to run those commands
func CreateCLI(commands ...Command) (func(in string), func(in prompt.Document) []prompt.Suggest) {
	var commandList Commands = commands
	executor := func(in string) {
		in = strings.TrimSpace(in)
		args := strings.Split(in, " ")
		command, err := commandList.Match(args[0])
		if err == nil {
			err := command.Executor(args)
			if err != nil {
				fmt.Printf("Error with previous command: %s\n", err)
			}
			return
		}
		switch args[0] {
		case "":
		case "help":
			commandList.GenerateHelp("Available commands:")
		case "exit":
			os.Exit(0)
		default:
			fmt.Println("Sorry, I don't understand.")
		}
	}
	completer := func(in prompt.Document) []prompt.Suggest {
		currentCommand := in.TextBeforeCursor()
		args := strings.Split(currentCommand, " ")
		match, err := commandList.Match(args[0])
		if err != nil {
			suggestions := commandList.GenerateSuggestions()
			return prompt.FilterHasPrefix(suggestions, in.GetWordBeforeCursor(), true)
		}
		if match.Completer != nil {
			return match.Completer(in)
		}
		return []prompt.Suggest{}
	}
	return executor, completer
}
func CreateCLI ( commands ... Command ) ( func ( in string ) , func ( in prompt . Document ) [ ] prompt . Suggest ) { var commandList Commands = commands executor := func ( in string ) { in = strings . TrimSpace ( in ) args := strings . Split ( in , " " ) command , err := commandList . Match ( args [ 0 ] ) if err == nil { err := command . Executor ( args ) if err != nil { fmt . Printf ( " \n " , err ) } return } switch args [ 0 ] { case " " : case " " : commandList . GenerateHelp ( " " ) case " " : os . Exit ( 0 ) default : fmt . Println ( " " ) } } completer := func ( in prompt . Document ) [ ] prompt . Suggest { currentCommand := in . TextBeforeCursor ( ) args := strings . Split ( currentCommand , " " ) match , err := commandList . Match ( args [ 0 ] ) if err != nil { suggestions := commandList . GenerateSuggestions ( ) return prompt . FilterHasPrefix ( suggestions , in . GetWordBeforeCursor ( ) , true ) } if match . Completer != nil { return match . Completer ( in ) } return [ ] prompt . Suggest { } } return executor , completer }
CreateCLI when provided a list of commands, generates a
Completer and Executor to run those commands
CreateCLI when provided a list of commands generates a Completer and Executor to run those commands
// iterates through each registered command until it // finds a match and runs its Executor // iterates through each registered command until it // finds a match and runs its Completer