Skip to content

Commit

Permalink
Fix autocomplete terms and help text to match available commands (#200)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
  • Loading branch information
mickmister and hanzei authored Feb 1, 2021
1 parent 5798bf3 commit 19d0766
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ validate-go-version: ## Validates the installed version of go against Mattermost
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
exit 1; \
fi

## Generates a tar bundle of the plugin for install.
.PHONY: bundle
bundle:
Expand Down Expand Up @@ -207,4 +207,4 @@ endif

# Help documentation à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
@cat Makefile | grep -v '\.PHONY' | grep -v '\help:' | grep -B1 -E '^[a-zA-Z0-9_.-]+:.*' | sed -e "s/:.*//" | sed -e "s/^## //" | grep -v '\-\-' | sed '1!G;h;$$!d' | awk 'NR%2{printf "\033[36m%-30s\033[0m",$$0;next;}1' | sort
@cat Makefile | grep -v '\.PHONY' | grep -v '\help:' | grep -B1 -E '^[a-zA-Z0-9_.-]+:.*' | sed -e "s/:.*//" | sed -e "s/^## //" | grep -v '\-\-' | sed '1!G;h;$$!d' | awk 'NR%2{printf "\033[36m%-30s\033[0m",$$0;next;}1' | sort
28 changes: 26 additions & 2 deletions server/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,39 @@ type RegisterFunc func(*model.Command) error

type handleFunc func(parameters ...string) (string, bool, error)

var cmds = []*model.AutocompleteData{
model.NewAutocompleteData("connect", "", "Connect to your Microsoft account"),
model.NewAutocompleteData("disconnect", "", "Disconnect from your Microsoft Account"),
model.NewAutocompleteData("summary", "", "View your events for today, or edit the settings for your daily summary."),
model.NewAutocompleteData("viewcal", "", "View your events for the upcoming week."),
model.NewAutocompleteData("settings", "", "Edit your user personal settings."),
model.NewAutocompleteData("subscribe", "", "Enable notifications for event invitations and updates."),
model.NewAutocompleteData("unsubscribe", "", "Disable notifications for event invitations and updates."),
model.NewAutocompleteData("autorespond", "[message]", "Set your auto-respond message."),
model.NewAutocompleteData("info", "", "Read information about this version of the plugin."),
model.NewAutocompleteData("help", "", "Read help text for the commands"),
}

// Register should be called by the plugin to register all necessary commands
func Register(registerFunc RegisterFunc) {
names := []string{}
for _, subCommand := range cmds {
names = append(names, subCommand.Trigger)
}

hint := "[" + strings.Join(names[:4], "|") + "...]"

cmd := model.NewAutocompleteData(config.CommandTrigger, hint, "Interact with your Outlook calendar.")
cmd.SubCommands = cmds

_ = registerFunc(&model.Command{
Trigger: config.CommandTrigger,
DisplayName: "Microsoft Calendar",
Description: "Interact with your outlook calendar.",
Description: "Interact with your Outlook calendar.",
AutoComplete: true,
AutoCompleteDesc: "help, info, connect, disconnect, connect_bot, disconnect_bot, subscribe, showcals, viewcal, createcal, deletecal, createevent, findmeetings, availability, autorespond, summary",
AutoCompleteDesc: strings.Join(names, ", "),
AutoCompleteHint: "(subcommand)",
AutocompleteData: cmd,
})
}

Expand Down
18 changes: 8 additions & 10 deletions server/command/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ import (
)

func (c *Command) help(parameters ...string) (string, bool, error) {
resp := getCommandText("help")
resp += getCommandText("connect")
resp += getCommandText("disconnect")
resp += getCommandText("settings - Edit your user personal settings.")
resp += getCommandText("autorespond <message> - Set your auto-respond message.")
resp += getCommandText("summary - View your events for today, or edit the settings for your daily summary.")
resp += getCommandText("viewcal - View your events for the upcoming week.")
resp += getCommandText("subscribe - Enable notifications for event invitations and updates.")
resp += getCommandText("unsubscribe - Disable notifications for event invitations and updates.")
resp += getCommandText("info - Read information about this version of the plugin.")
resp := ""
for _, cmd := range cmds {
desc := cmd.Trigger
if cmd.HelpText != "" {
desc += " - " + cmd.HelpText
}
resp += getCommandText(desc)
}
return resp, false, nil
}

Expand Down

0 comments on commit 19d0766

Please sign in to comment.