The MOPS SDK provides a simple and powerful way to create plugins for the MOPS (Micro Operations System).
MOPS is a terminal-based operations management system that supports extensible plugins. This SDK allows you to create plugins that can:
- Provide dynamic menu entries
- Execute custom actions
- Add interactive streaming functions
- Extend CLI commands
- Add menu entries to existing menus
go get github.com/totmicro/mops-sdk
Here's a simple "Hello World" plugin:
package main
import (
"fmt"
"github.com/totmicro/mops-sdk"
)
func main() {
plugin := sdk.NewPluginBuilder("hello-world", "1.0.0", "A simple hello world plugin").
SetAuthor("Your Name").
SetLicense("MIT").
WithSimpleExecutor("hello", func(entry sdk.MenuEntry, input string) sdk.ActionResult {
name := input
if name == "" {
name = "World"
}
return sdk.ActionResult{
Success: true,
Output: fmt.Sprintf("Hello, %s!", name),
ShowOutput: true,
}
}).
Build()
sdk.Main(plugin)
}
plugin := sdk.NewPluginBuilder("plugin-name", "1.0.0", "Plugin description")
plugin.SetAuthor("Author Name").
SetLicense("MIT").
SetHomepage("https://github.com/user/plugin").
SetMopsVersions("1.0.0", "2.0.0").
AddTag("utility").
AddDependency("some-other-plugin")
plugin.WithSimpleExecutor("my-action", func(entry sdk.MenuEntry, input string) sdk.ActionResult {
return sdk.ActionResult{
Success: true,
Output: "Action executed successfully",
ShowOutput: true,
}
})
plugin.WithSimpleProvider("my-provider", "Provides dynamic entries", func(param string) ([]sdk.MenuEntry, error) {
return []sdk.MenuEntry{
{
Key: "1",
Label: "Option 1",
Action: "my-action",
},
{
Key: "2",
Label: "Option 2",
Action: "my-action",
},
}, nil
})
plugin.WithInteractiveFunction("my-interactive", func(ctx context.Context, outputChan chan<- string, inputChan <-chan string, params map[string]interface{}) error {
outputChan <- "Enter your name:"
select {
case name := <-inputChan:
outputChan <- fmt.Sprintf("Hello, %s!", name)
case <-ctx.Done():
return ctx.Err()
}
return nil
})
plugin.WithCLICommand("hello", "Print a greeting", func(args []string) error {
name := "World"
if len(args) > 0 {
name = args[0]
}
fmt.Printf("Hello, %s!\n", name)
return nil
})
A typical plugin project structure:
my-plugin/
├── main.go # Plugin entry point
├── go.mod # Go module file
├── plugin.yaml # Plugin metadata (optional)
├── Makefile # Build configuration
├── README.md # Plugin documentation
└── internal/ # Internal plugin code
├── core/ # Core plugin logic
├── cli/ # CLI command handlers
└── ui/ # UI-related code
go build -o my-plugin .
mkdir -p ~/.mops/plugins
cp my-plugin ~/.mops/plugins/
# Linux AMD64
GOOS=linux GOARCH=amd64 go build -o my-plugin-linux-amd64 .
# macOS AMD64
GOOS=darwin GOARCH=amd64 go build -o my-plugin-darwin-amd64 .
# Windows AMD64
GOOS=windows GOARCH=amd64 go build -o my-plugin-windows-amd64.exe .
name: my-plugin
version: 1.0.0
description: "My awesome plugin"
author: "Your Name"
license: "MIT"
homepage: "https://github.com/user/my-plugin"
tags:
- "utility"
- "example"
# MOPS version compatibility
mops_version:
min_version: "1.0.0"
max_version: "2.0.0"
# Build targets
build_targets:
- os: linux
arch: amd64
output: my-plugin-linux-amd64
- os: darwin
arch: amd64
output: my-plugin-darwin-amd64
- os: windows
arch: amd64
output: my-plugin-windows-amd64.exe
# Default configuration
default_config:
enabled: true
timeout: 30
# CLI commands
cli_commands:
- name: hello
description: "Print a greeting"
usage: "mops plugin my-plugin hello [name]"
examples:
- "mops plugin my-plugin hello"
- "mops plugin my-plugin hello World"
Check the examples/
directory for complete plugin examples:
hello-world/
- Basic plugin with action executorfile-manager/
- Plugin with dynamic providersinteractive-demo/
- Plugin with interactive functionscli-tools/
- Plugin with CLI commands
Plugin
- Main plugin interfacePluginInfo
- Plugin metadataActionResult
- Result of action executionMenuEntry
- Menu entry definitionDynamicProvider
- Interface for dynamic menu providersActionExecutor
- Interface for action executorsInteractiveGoFunction
- Interactive function type
NewPluginBuilder(name, version, description)
- Create new builderSetAuthor(author)
- Set plugin authorSetLicense(license)
- Set plugin licenseSetHomepage(url)
- Set plugin homepageAddTag(tag)
- Add plugin tagWithSimpleExecutor(type, handler)
- Add action executorWithSimpleProvider(name, description, handler)
- Add dynamic providerWithInteractiveFunction(name, handler)
- Add interactive functionWithCLICommand(name, description, handler)
- Add CLI commandBuild()
- Build the plugin
MIT License - see LICENSE file for details.