gosh icon indicating copy to clipboard operation
gosh copied to clipboard

More information on plugins?

Open Merith-TK opened this issue 4 years ago • 0 comments

Is it possible to get more information on this? I dont fully understand the syntax or the concepts behind it,

here is where im at,

package main

import (
	"context"
	"fmt"
	"io"

	"github.com/Merith-TK/gosh/api"
)

type customCmd string

func (t customCmd) Name() string      { return string(t) }
func (t customCmd) Usage() string     { return `custom` }
func (t customCmd) ShortDesc() string { return `prints greeting "custom there"` }
func (t customCmd) LongDesc() string  { return t.ShortDesc() }
func (t customCmd) Exec(ctx context.Context, args []string) (context.Context, error) {
	out := ctx.Value("gosh.stdout").(io.Writer)
	fmt.Fprintln(out, "custom there")
	return ctx, nil
}

// command module
type customCmds struct{}

func (t *customCmds) Init(ctx context.Context) error {
	out := ctx.Value("gosh.stdout").(io.Writer)
	fmt.Fprintln(out, "custom module loaded OK")
	return nil
}

func (t *customCmds) Registry() map[string]api.Command {
	return map[string]api.Command{
		"custom": customCmd("custom"),
	}
}

// Commands just custom
var Commands customCmds

This is a modifcation of testcmd.go I understand everything up to line 17,

i dont understand how to declare and call upon functions entirely for this plugin in a easy to understand method,

Merith-TK avatar Jan 08 '20 17:01 Merith-TK