Skip to content

totmicro/mops-sdk

Repository files navigation

MOPS SDK

The MOPS SDK provides a simple and powerful way to create plugins for the MOPS (Micro Operations System).

Overview

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

Installation

go get github.com/totmicro/mops-sdk

Quick Start

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 Builder API

Creating a Plugin

plugin := sdk.NewPluginBuilder("plugin-name", "1.0.0", "Plugin description")

Setting Metadata

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")

Adding Functionality

Simple Action Executor

plugin.WithSimpleExecutor("my-action", func(entry sdk.MenuEntry, input string) sdk.ActionResult {
    return sdk.ActionResult{
        Success:    true,
        Output:     "Action executed successfully",
        ShowOutput: true,
    }
})

Dynamic Provider

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
})

Interactive Function

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
})

CLI Command

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
})

Plugin Structure

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

Building and Distribution

Local Development

go build -o my-plugin .
mkdir -p ~/.mops/plugins
cp my-plugin ~/.mops/plugins/

Multi-platform Build

# 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 .

Plugin Metadata (plugin.yaml)

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"

Examples

Check the examples/ directory for complete plugin examples:

  • hello-world/ - Basic plugin with action executor
  • file-manager/ - Plugin with dynamic providers
  • interactive-demo/ - Plugin with interactive functions
  • cli-tools/ - Plugin with CLI commands

API Reference

Core Types

  • Plugin - Main plugin interface
  • PluginInfo - Plugin metadata
  • ActionResult - Result of action execution
  • MenuEntry - Menu entry definition
  • DynamicProvider - Interface for dynamic menu providers
  • ActionExecutor - Interface for action executors
  • InteractiveGoFunction - Interactive function type

Plugin Builder Methods

  • NewPluginBuilder(name, version, description) - Create new builder
  • SetAuthor(author) - Set plugin author
  • SetLicense(license) - Set plugin license
  • SetHomepage(url) - Set plugin homepage
  • AddTag(tag) - Add plugin tag
  • WithSimpleExecutor(type, handler) - Add action executor
  • WithSimpleProvider(name, description, handler) - Add dynamic provider
  • WithInteractiveFunction(name, handler) - Add interactive function
  • WithCLICommand(name, description, handler) - Add CLI command
  • Build() - Build the plugin

License

MIT License - see LICENSE file for details.

About

Official SDK for MOPS plugin development

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages