with about plugins
This commit is contained in:
@@ -3,48 +3,18 @@ package char
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.front.kjuulh.io/kjuulh/char/pkg/plugins/provider"
|
||||
"git.front.kjuulh.io/kjuulh/char/pkg/register"
|
||||
"git.front.kjuulh.io/kjuulh/char/pkg/schema"
|
||||
"git.front.kjuulh.io/kjuulh/char/pkg/charcontext"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func NewLsCommand() *cobra.Command {
|
||||
gpp := provider.NewGitPluginProvider()
|
||||
func NewLsCommand(charctx *charcontext.CharContext) *cobra.Command {
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "ls",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
ctx := cmd.Context()
|
||||
|
||||
s, err := schema.ParseFile(ctx, ".char.yml")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
plugins, err := s.GetPlugins(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = gpp.FetchPlugins(ctx, s.Registry, plugins)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
builder := register.NewPluginRegisterBuilder()
|
||||
|
||||
for name, plugin := range plugins {
|
||||
builder = builder.Add(name.Hash(), plugin.Opts.Path)
|
||||
}
|
||||
|
||||
r, err := builder.Build(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
about, err := r.About(ctx)
|
||||
about, err := charctx.About(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -53,6 +23,36 @@ func NewLsCommand() *cobra.Command {
|
||||
fmt.Printf("plugin: %s\n", a.Name)
|
||||
fmt.Printf("\tversion: %s\n", a.Version)
|
||||
fmt.Printf("\tabout: %s\n", a.About)
|
||||
if len(a.Vars) > 0 {
|
||||
fmt.Println("\tVars:")
|
||||
for _, av := range a.Vars {
|
||||
fmt.Printf("\t\t%s\n", av)
|
||||
}
|
||||
}
|
||||
if len(a.Commands) > 0 {
|
||||
fmt.Println("\tCommands:")
|
||||
for _, ac := range a.Commands {
|
||||
fmt.Printf("\t\t%s", ac)
|
||||
if len(ac.Args) == 0 {
|
||||
continue
|
||||
}
|
||||
for _, aca := range ac.Args {
|
||||
isrequired := false
|
||||
for _, acr := range ac.Required {
|
||||
if acr == aca {
|
||||
isrequired = true
|
||||
}
|
||||
}
|
||||
if isrequired {
|
||||
fmt.Printf("\t\t\t%s: required\n", aca)
|
||||
} else {
|
||||
fmt.Printf("\t\t\t%s\n", aca)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user