Sign in

    moonbitstack/moonctl/plugin does not have a README file

    GenFile

    pub(all) struct GenFile {
    path : String
    content : String
    }

    One file a plugin asks mctl to write: a destination path (relative to the output directory) and its full content.

    Plugin

    pub(all) struct Plugin {
    api :
    Spec

    api_file_path : String
    style : String
    dir : String
    }

    What a plugin is handed on stdin (← goctl's plugin.Plugin): the parsed spec under api, the .api file it was read from, the --style naming template, and the directory the generated tree goes under.

    gen_files_to_json

    fn gen_files_to_json(files : Array[GenFile]) -> Json

    Serialise a list of generated files into the plugin-reply JSON — the writer a MoonBit plugin uses on its stdout. Emits the {"files": [...]} envelope.

    parse_gen_files

    fn parse_gen_files(j : Json) -> Array[GenFile]

    Parse a plugin's stdout into the files to write. Two shapes are accepted: a bare array [{path, content}, …], or an object {"files": [ … ]} (goctl-style envelope). An element missing path or content is skipped. The list preserves the plugin's order.

    plugin_argv

    fn plugin_argv(invocation : String) -> (String, Array[String])

    Split a plugin invocation into the program to run and the arguments to run it with, the way goctl reads its -plugin value: the first whitespace-separated word is the executable, the rest are its argv. A quoted word keeps its spaces.

    plugin_from_json

    fn plugin_from_json(j : Json) -> Plugin

    Read the request a plugin was handed on stdin. Missing members degrade to empty rather than raising, so a hand-written request still parses.

    plugin_request

    fn plugin_request(spec :
    Spec
    , api_file_path? : String, style? : String, dir? : String) -> String

    The plugin request as a two-space-indented JSON string, ready to write to the plugin's stdin: goctl's four keys — the spec under Api, plus the file it was read from, the --style template and the output directory, which is everything a plugin needs to decide where its output goes and what to call it.

    spec_from_json

    fn spec_from_json(j : Json) ->
    Spec

    Reconstruct a Spec from the request JSON — the reader a plugin written in MoonBit uses on its stdin. The whole request ({Api, ApiFilePath, Style, Dir}) and a bare spec are both accepted, so a plugin that wants nothing but the routes need not unwrap the envelope. Missing or mistyped members degrade to empty rather than raising, so a partial request still parses.

    spec_to_json

    fn spec_to_json(spec :
    Spec
    ) -> Json

    Serialise a Spec into the plugin request JSON. The shape mirrors the Spec itself — service, routes (verb/path/handler/summary, plus the group the route was declared under), types (name plus fields of name/type) and groups — so a plugin in any language parses it with an ordinary JSON reader. type_ is written as type, the name a caller expects.

    Source Files