@@ -4,13 +4,15 @@ Copyright © 2023 NAME HERE <EMAIL ADDRESS>
44package cmd
55
66import (
7+ "bytes"
78 "encoding/json"
9+ "fmt"
810 "github.com/manifoldco/promptui"
9- "github.com/opq-osc/Yui/plugin/meta"
1011 "github.com/spf13/cobra"
1112 "os"
1213 "os/exec"
1314 "path/filepath"
15+ "regexp"
1416 "strings"
1517)
1618
@@ -21,25 +23,27 @@ var newCmd = &cobra.Command{
2123 Long : `创建一个新的插件` ,
2224 RunE : func (cmd * cobra.Command , args []string ) error {
2325 prompt := promptui.Prompt {
24- Label : "plugin name" ,
26+ Label : "plugin name" ,
27+ HideEntered : true ,
28+ Validate : ValidAllAlpha ,
2529 }
2630 var err error
27- pluginInfo := & meta. PluginMeta {}
31+ pluginInfo := & BuildMetaInfo {}
2832 pluginInfo .PluginName , err = prompt .Run ()
2933 if err != nil {
3034 return err
3135 }
32- prompt = promptui.Prompt {Label : "plugin description" }
36+ prompt = promptui.Prompt {Label : "plugin description" , HideEntered : true }
3337 pluginInfo .Description , err = prompt .Run ()
3438 if err != nil {
3539 return err
3640 }
37- prompt = promptui.Prompt {Label : "author" }
41+ prompt = promptui.Prompt {Label : "author" , HideEntered : true }
3842 pluginInfo .Author , err = prompt .Run ()
3943 if err != nil {
4044 return err
4145 }
42- prompt = promptui.Prompt {Label : "author url" }
46+ prompt = promptui.Prompt {Label : "author url" , HideEntered : true }
4347 pluginInfo .Url , err = prompt .Run ()
4448 if err != nil {
4549 return err
@@ -71,7 +75,12 @@ var newCmd = &cobra.Command{
7175 if err != nil {
7276 return err
7377 }
74- err = os .WriteFile (filepath .Join (pluginInfo .PluginName , "meta.json" ), []byte (metaInfo ), 0777 )
78+ var buf bytes.Buffer
79+ err = json .Indent (& buf , metaInfo , "" , "\t " )
80+ if err != nil {
81+ return err
82+ }
83+ err = os .WriteFile (filepath .Join (pluginInfo .PluginName , "meta.json" ), buf .Bytes (), 0777 )
7584 if err != nil {
7685 return err
7786 }
@@ -93,12 +102,18 @@ func init() {
93102 // newCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
94103}
95104
105+ func ValidAllAlpha (s string ) error {
106+ if match , _ := regexp .MatchString (`^[A-Za-z0-9]+$` , s ); match {
107+ return nil
108+ }
109+ return fmt .Errorf ("err" )
110+ }
111+
96112var goFile = `//go:build tinygo.wasm
97113
98114package main
99115
100116import (
101- "github.com/opq-osc/Yui/plugin/meta"
102117 "github.com/opq-osc/Yui/proto"
103118 "context"
104119 "github.com/knqyf263/go-plugin/types/known/emptypb"
0 commit comments