Skip to content

Commit

Permalink
Some improvements in autocompletion (#163)
Browse files Browse the repository at this point in the history
* Some improvements on the autocompletion

* feat: Add IconURL to cloud slash command

* refactor: Remove unused icon URL from cloud command configuration

* feat: Add base64-encoded icon data for cloud command autocomplete

* feat: Read app bar icon from plugin bundle dynamically

* fixing import

* improving the autocompletion flags

* Apply suggestions from code review

Co-authored-by: Gabe Jackson <[email protected]>

---------

Co-authored-by: Gabe Jackson <[email protected]>
  • Loading branch information
jespino and gabrieljackson authored Dec 2, 2024
1 parent f0642bf commit ca2d8bf
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 35 deletions.
169 changes: 134 additions & 35 deletions server/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ info

func (p *Plugin) getCommand() *model.Command {
return &model.Command{
Trigger: "cloud",
DisplayName: "Mattermost Private Cloud",
Description: "This command allows spinning up and down Mattermost installations using Mattermost Private Cloud.",
AutoComplete: p.getConfiguration().EnableCommandAutocompletion,
AutoCompleteDesc: "Available commands: create, list, update, mmcli, mmctl, delete, share, unshare, restart, hibernate, wake-up, info, import",
AutoCompleteHint: "[command]",
Trigger: "cloud",
DisplayName: "Mattermost Private Cloud",
Description: "This command allows spinning up and down Mattermost installations using Mattermost Private Cloud.",
AutoComplete: p.getConfiguration().EnableCommandAutocompletion,
AutoCompleteDesc: "Available commands: create, list, update, mmcli, mmctl, delete, share, unshare, restart, hibernate, wake-up, info, import",
AutoCompleteHint: "[command]",
AutocompleteIconData: p.appBarIconData,
AutocompleteData: &model.AutocompleteData{
Trigger: "cloud",
SubCommands: []*model.AutocompleteData{
Expand All @@ -95,16 +96,37 @@ func (p *Plugin) getCommand() *model.Command {
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "name",
Hint: "[name]",
Pattern: "^[a-zA-Z0-9-]+$",
},
HelpText: "Name of the installation",
Required: true,
},
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "license",
Type: model.AutocompleteArgTypeStaticList,
Data: &model.AutocompleteStaticListArg{
PossibleArguments: []model.AutocompleteListItem{
{
Item: "e20",
HelpText: "E20 License",
},
{
Item: "e10",
HelpText: "E10 License",
},
{
Item: "te",
HelpText: "Team Edition License",
},
{
Item: "enterprise",
HelpText: "Enterprise Edition License",
},
{
Item: "professional",
HelpText: "Professional Edition License",
},
},
},
Name: "license",
HelpText: "The Mattermost license to use. Can be 'enterprise', 'professional', 'e20', 'e10', or 'te' (default \"enterprise\")",
Expand All @@ -116,19 +138,36 @@ func (p *Plugin) getCommand() *model.Command {
Required: false,
},
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "affinity",
Pattern: "^(isolated|multitenant)$",
Type: model.AutocompleteArgTypeStaticList,
Data: &model.AutocompleteStaticListArg{
PossibleArguments: []model.AutocompleteListItem{
{
Item: "isolated",
HelpText: "Isolated",
},
{
Item: "multitenant",
HelpText: "Multi-tenant",
},
},
},
Name: "affinity",
HelpText: "Whether the installation is isolated in it's own cluster or shares ones. Can be 'isolated' or 'multitenant' (default \"multitenant\")",
Required: false,
},
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "database",
Type: model.AutocompleteArgTypeStaticList,
Data: &model.AutocompleteStaticListArg{
PossibleArguments: []model.AutocompleteListItem{
{
Item: "aws-multitenant-rds-postgres-pgbouncer",
HelpText: "RDS Postgres with pgbouncer proxy connections",
},
{
Item: "aws-rds",
HelpText: "RDS MySQL",
},
},
},
Name: "database",
HelpText: "Specify the backing database. Can be 'aws-multitenant-rds-postgres-pgbouncer' (RDS Postgres with pgbouncer proxy connections), 'aws-rds' (RDS MySQL). (default \"aws-multitenant-rds-postgres-pgbouncer\")",
Expand All @@ -149,9 +188,22 @@ func (p *Plugin) getCommand() *model.Command {
Required: false,
},
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "filestore",
Type: model.AutocompleteArgTypeStaticList,
Data: &model.AutocompleteStaticListArg{
PossibleArguments: []model.AutocompleteListItem{
{
Item: "bifrost",
HelpText: "Shared S3 bucket with access via bifrost",
},
{
Item: "aws-multitenant-s3",
HelpText: "S3 Shared Bucket",
},
{
Item: "aws-s3",
HelpText: "S3 Bucket",
},
},
},
Name: "filestore",
HelpText: "Specify the backing file store. Can be 'bifrost' (S3 Shared Bucket), 'aws-multitenant-s3' (S3 Shared Bucket), 'aws-s3' (S3 Bucket). (default \"bifrost\")",
Expand All @@ -167,9 +219,18 @@ func (p *Plugin) getCommand() *model.Command {
Required: false,
},
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "size",
Type: model.AutocompleteArgTypeStaticList,
Data: &model.AutocompleteStaticListArg{
PossibleArguments: []model.AutocompleteListItem{
{
Item: "miniSingleton",
HelpText: "Mini Singleton instance",
},
{
Item: "miniHA",
HelpText: "Mini cluster made of two servers",
},
},
},
Name: "size",
HelpText: "Size of the Mattermost installation e.g. 'miniSingleton' or 'miniHA' (default \"miniSingleton\")",
Expand Down Expand Up @@ -204,7 +265,7 @@ func (p *Plugin) getCommand() *model.Command {
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "name",
Hint: "[name]",
Pattern: "^[a-zA-Z0-9-]+$",
},
HelpText: "Name of the installation to update",
Expand All @@ -216,6 +277,31 @@ func (p *Plugin) getCommand() *model.Command {
Required: false,
},
{
Type: model.AutocompleteArgTypeStaticList,
Data: &model.AutocompleteStaticListArg{
PossibleArguments: []model.AutocompleteListItem{
{
Item: "e20",
HelpText: "E20 License",
},
{
Item: "e10",
HelpText: "E10 License",
},
{
Item: "te",
HelpText: "Team Edition License",
},
{
Item: "enterprise",
HelpText: "Enterprise Edition License",
},
{
Item: "professional",
HelpText: "Professional Edition License",
},
},
},
Name: "license",
HelpText: "The enterprise license to use. Can be 'enterprise', 'professional', 'e20', 'e10', or 'te'",
Required: false,
Expand All @@ -236,6 +322,19 @@ func (p *Plugin) getCommand() *model.Command {
Required: false,
},
{
Type: model.AutocompleteArgTypeStaticList,
Data: &model.AutocompleteStaticListArg{
PossibleArguments: []model.AutocompleteListItem{
{
Item: "miniSingleton",
HelpText: "Mini Singleton instance",
},
{
Item: "miniHA",
HelpText: "Mini cluster made of two servers",
},
},
},
Name: "size",
HelpText: "Size of the Mattermost installation e.g. 'miniSingleton' or 'miniHA'",
Required: false,
Expand All @@ -249,7 +348,7 @@ func (p *Plugin) getCommand() *model.Command {
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "name",
Hint: "[name]",
Pattern: "^[a-zA-Z0-9-]+$",
},
HelpText: "Name of the installation to share",
Expand All @@ -269,7 +368,7 @@ func (p *Plugin) getCommand() *model.Command {
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "name",
Hint: "[name]",
Pattern: "^[a-zA-Z0-9-]+$",
},
HelpText: "Name of the installation to unshare",
Expand All @@ -284,7 +383,7 @@ func (p *Plugin) getCommand() *model.Command {
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "name",
Hint: "[name]",
Pattern: "^[a-zA-Z0-9-]+$",
},
HelpText: "Name of the installation to restart",
Expand All @@ -299,7 +398,7 @@ func (p *Plugin) getCommand() *model.Command {
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "name",
Hint: "[name]",
Pattern: "^[a-zA-Z0-9-]+$",
},
HelpText: "Name of the installation to hibernate",
Expand All @@ -314,7 +413,7 @@ func (p *Plugin) getCommand() *model.Command {
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "name",
Hint: "[name]",
Pattern: "^[a-zA-Z0-9-]+$",
},
HelpText: "Name of the installation to wake up",
Expand All @@ -329,7 +428,7 @@ func (p *Plugin) getCommand() *model.Command {
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "name",
Hint: "[name]",
Pattern: "^[a-zA-Z0-9-]+$",
},
HelpText: "Name of the installation to delete",
Expand All @@ -348,7 +447,7 @@ func (p *Plugin) getCommand() *model.Command {
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "DNS",
Hint: "[DNS]",
},
HelpText: "DNS value of the installation to import",
Required: true,
Expand All @@ -362,7 +461,7 @@ func (p *Plugin) getCommand() *model.Command {
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "name",
Hint: "[name]",
Pattern: "^[a-zA-Z0-9-]+$",
},
HelpText: "Name of the installation to run CLI commands on",
Expand All @@ -371,7 +470,7 @@ func (p *Plugin) getCommand() *model.Command {
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "mattermost-subcommand",
Hint: "[mattermost-subcommand]",
},
HelpText: "The Mattermost CLI subcommand to run",
Required: true,
Expand All @@ -385,7 +484,7 @@ func (p *Plugin) getCommand() *model.Command {
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "name",
Hint: "[name]",
Pattern: "^[a-zA-Z0-9-]+$",
},
HelpText: "Name of the installation to run mmctl commands on",
Expand All @@ -394,7 +493,7 @@ func (p *Plugin) getCommand() *model.Command {
{
Type: model.AutocompleteArgTypeText,
Data: &model.AutocompleteTextArg{
Hint: "mmctl-subcommand",
Hint: "[mmctl-subcommand]",
},
HelpText: "The mmctl subcommand to run",
Required: true,
Expand Down
9 changes: 9 additions & 0 deletions server/plugin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"encoding/base64"
"io/ioutil"
"path/filepath"
"strings"
Expand Down Expand Up @@ -29,6 +30,7 @@ type Plugin struct {
// setConfiguration for usage.
configuration *configuration

appBarIconData string
latestMattermostVersion *latestMattermostVersionCache
}

Expand Down Expand Up @@ -125,6 +127,13 @@ func (p *Plugin) OnActivate() error {
return errors.Wrap(appErr, "couldn't set profile image")
}

// Read the app bar icon for command autocomplete
appBarIcon, err := ioutil.ReadFile(filepath.Join(bundlePath, "public", "app-bar-icon.png"))
if err != nil {
return errors.Wrap(err, "couldn't read app bar icon")
}
p.appBarIconData = "data:image/png;base64," + base64.StdEncoding.EncodeToString(appBarIcon)

p.setCloudClient()
p.dockerClient = NewDockerClient()
return p.API.RegisterCommand(p.getCommand())
Expand Down

0 comments on commit ca2d8bf

Please sign in to comment.