mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-21 02:23:20 +00:00
* Iterating on AI/MCP docs * docs iterate * mlr skill * docs iterate * agent-skill.md.in * docs iterate * docs iterate * edits * codex/gemini info
95 lines
2.6 KiB
Go
95 lines
2.6 KiB
Go
// Support for Miller regression testing. Originally bash scripts; ported to Go
|
|
// for ease of Windows-native testing.
|
|
|
|
package terminals
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"runtime"
|
|
|
|
"github.com/johnkerl/miller/v6/pkg/terminals/completion"
|
|
"github.com/johnkerl/miller/v6/pkg/terminals/help"
|
|
"github.com/johnkerl/miller/v6/pkg/terminals/mcp"
|
|
"github.com/johnkerl/miller/v6/pkg/terminals/registry"
|
|
"github.com/johnkerl/miller/v6/pkg/terminals/regtest"
|
|
"github.com/johnkerl/miller/v6/pkg/terminals/repl"
|
|
"github.com/johnkerl/miller/v6/pkg/terminals/script"
|
|
"github.com/johnkerl/miller/v6/pkg/terminals/skill"
|
|
"github.com/johnkerl/miller/v6/pkg/version"
|
|
)
|
|
|
|
// tTerminalMain is a function-pointer type for the entrypoint handler for a given terminal,
|
|
// such as 'help' or 'regtest'.
|
|
type tTerminalMain func(args []string) int
|
|
|
|
type tTerminalLookupEntry struct {
|
|
name string
|
|
main tTerminalMain
|
|
}
|
|
|
|
// _TERMINAL_LOOKUP_TABLE is the lookup table for terminals. We get a Golang
|
|
// "initialization loop" if this is defined statically. So, we use a "package
|
|
// init" function.
|
|
var _TERMINAL_LOOKUP_TABLE = []tTerminalLookupEntry{}
|
|
|
|
func init() {
|
|
_TERMINAL_LOOKUP_TABLE = []tTerminalLookupEntry{
|
|
{registry.TerminalList, terminalListMain},
|
|
{registry.Completion, completion.CompletionMain},
|
|
{registry.Help, help.HelpMain},
|
|
{registry.Mcp, mcp.McpMain},
|
|
{registry.Regtest, regtest.RegTestMain},
|
|
{registry.Repl, repl.ReplMain},
|
|
{registry.Script, script.ScriptMain},
|
|
{registry.Skill, skill.SkillMain},
|
|
{registry.Version, showVersion},
|
|
{registry.Which, help.WhichMain},
|
|
}
|
|
}
|
|
|
|
func Dispatchable(arg string) bool {
|
|
for _, entry := range _TERMINAL_LOOKUP_TABLE {
|
|
if arg == entry.name {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func Dispatch(args []string) {
|
|
if len(args) < 1 {
|
|
return
|
|
}
|
|
terminal := args[0]
|
|
|
|
for _, entry := range _TERMINAL_LOOKUP_TABLE {
|
|
if terminal == entry.name {
|
|
os.Exit(entry.main(args))
|
|
}
|
|
}
|
|
fmt.Fprintf(os.Stderr, "mlr: terminal \"%s\" not found.\n", terminal)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// terminalListMain is the handler for 'mlr terminal-list'.
|
|
func terminalListMain(args []string) int {
|
|
ShowTerminalEntries(os.Stdout)
|
|
return 0
|
|
}
|
|
|
|
// ShowTerminalEntries is a symbol is exported for 'mlr --help'.
|
|
func ShowTerminalEntries(o *os.File) {
|
|
fmt.Fprintf(o, "Available subcommands:\n")
|
|
for _, entry := range _TERMINAL_LOOKUP_TABLE {
|
|
fmt.Fprintf(o, " %s\n", entry.name)
|
|
}
|
|
|
|
fmt.Fprintf(o, "For more information, please invoke mlr {subcommand} --help.\n")
|
|
}
|
|
|
|
func showVersion(args []string) int {
|
|
fmt.Printf("mlr version %s for %s/%s/%s\n",
|
|
version.STRING, runtime.GOOS, runtime.GOARCH, runtime.Version())
|
|
return 0
|
|
}
|