fix minor bugs and add do

This commit is contained in:
2022-11-02 22:49:32 +01:00
parent 9a0002b34f
commit 9b95267eeb
7 changed files with 103 additions and 12 deletions

View File

@@ -64,3 +64,7 @@ func (cc *CharContext) Close() {
func (cc *CharContext) About(ctx context.Context) ([]register.AboutItem, error) {
return cc.pluginRegister.About(ctx)
}
func (cc *CharContext) Do(ctx context.Context, argName string, commandName string) error {
return nil
}

View File

@@ -2,6 +2,7 @@ package provider
import (
"context"
"errors"
"fmt"
"log"
"os"
@@ -27,22 +28,28 @@ func (gpp *GitPluginProvider) FetchPlugins(ctx context.Context, registry string,
}
}
if err := os.MkdirAll(baseDir, 0755); err != nil {
return err
return fmt.Errorf("path already exists cannot create: %w", err)
}
for n, plugin := range plugins {
n, plugin := n, plugin
errgroup.Go(func() error {
log.Printf("fetching git plugin repo: %s", n)
return gpp.FetchPlugin(
ctx,
registry,
plugin,
fmt.Sprintf(
"%s/%s",
strings.TrimRight(baseDir, "/"), n.Hash(),
),
dest := fmt.Sprintf(
"%s/%s",
strings.TrimRight(baseDir, "/"), n.Hash(),
)
if _, err := os.Stat(dest); errors.Is(err, os.ErrNotExist) {
log.Printf("fetching git plugin repo: %s", n)
return gpp.FetchPlugin(
ctx,
registry,
plugin,
dest,
)
}
return nil
})
}
@@ -66,6 +73,7 @@ func (gpp *GitPluginProvider) FetchPlugin(ctx context.Context, registry string,
output, err := exec.Command(
"git",
"clone",
"--depth=1",
cloneUrl,
dest,
).CombinedOutput()

View File

@@ -44,7 +44,7 @@ func (pr *PluginRegisterBuilder) Build(ctx context.Context) (*PluginRegister, er
name, p := name, p
errgroup.Go(func() error {
pluginPath := fmt.Sprintf(".char/plugins/%s/dist/cmd", name)
pluginPath := fmt.Sprintf(".char/plugins/%s/dist/plugin", name)
_, err := os.Stat(pluginPath)
if err != nil || os.Getenv("CHAR_DEV_MODE") == "true" {