We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do you have an example with help command?
So, for example, if I do
help i would my shell to show all valid commands
help commandA i would like to show help message for "commandA"
or
help commandA subcommandA would show help command for commandA subcommandA (i think you get the point)
Is that possible, if so do you have some example code?
The text was updated successfully, but these errors were encountered:
go-prompt just provides prompt.Document object to completer functions. And you can access all buffer information via it.
prompt.Document
When you input a following text(period means the cursor position):
help commandA . <- cursor position
In this case,
document.TextBeforeCursor()
help comm
document.GetWordBeforeCursor()
comm
So you can implement that like:
func completer(d prompt.Document) []prompt.Suggest { tbc := d.TextBeforeCursor() args := strings.Split(tbc, " ") depth := len() switch depth { case 1: suggests := []prompt.Suggest{ {Text: "help", "i would my shell to show all valid commands"}, {Text: "commandA", "..."}, } return prompt.FilterHasPrefix(suggests, d.GetWordBeforeCursor()) case 2: switch args[0] { case "help": suggests := []prompt.Suggest{ {Text: "commandA", "i would like to show help message for "commandA""}, {Text: "commandB", "..."}, } return prompt.FilterHasPrefix(suggests, d.GetWordBeforeCursor()) case "commandA": // return subcommand suggestions of commandA } case 3: switch strings.Join(args[:1], " ") { case "help commandA": suggests := []prompt.Suggest{ {Text: "subcommandA", "would show help command for commandA subcommandA"}, {Text: "subcommandB", "..."}, } return suggests } } }
Sorry, something went wrong.
No branches or pull requests
Do you have an example with help command?
So, for example, if I do
or
Is that possible, if so do you have some example code?
The text was updated successfully, but these errors were encountered: