Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More information on plugins? #8

Open
Merith-TK opened this issue Jan 8, 2020 · 0 comments
Open

More information on plugins? #8

Merith-TK opened this issue Jan 8, 2020 · 0 comments

Comments

@Merith-TK
Copy link
Contributor

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant