diff --git a/cmd/function.go b/cmd/function.go index c94bb115..34c02077 100644 --- a/cmd/function.go +++ b/cmd/function.go @@ -18,6 +18,7 @@ package cmd import ( "context" + "errors" "fmt" "go/ast" "go/doc" @@ -44,14 +45,27 @@ func createFunctionCmd() (c *cobra.Command) { } flags := c.Flags() flags.StringVarP(&opt.feature, "feature", "", "", "The feature query") + flags.StringVarP(&opt.extensionFile, "extension-file", "", "", "The extension file") return } type funcPrinterOption struct { - feature string + feature string + extensionFile string } func (o *funcPrinterOption) runE(cmd *cobra.Command, args []string) (err error) { + if o.extensionFile != "" { + var tpl *render.UserDefinedTemplates + if tpl, err = render.ParseUserDefinedTemplatesFromFile(o.extensionFile); err != nil { + return + } + + if err = errors.Join(err, tpl.Validate(), tpl.ConflictWith(render.FuncMap())); err != nil { + return + } + } + if len(args) > 0 { name := args[0] filterAndPrint(cmd, name) diff --git a/cmd/function_test.go b/cmd/function_test.go index 05a72b41..ca790aec 100644 --- a/cmd/function_test.go +++ b/cmd/function_test.go @@ -29,6 +29,7 @@ func TestCreateFunctionCommand(t *testing.T) { tests := []struct { name string args []string + hasErr bool verify func(t *testing.T, output string) }{{ name: "normal", @@ -61,6 +62,13 @@ func TestCreateFunctionCommand(t *testing.T) { assert.Equal(t, `{{generateJSONString "name"}} `, output) }, + }, { + name: "verify template functions with error", + args: []string{"func", "--extension-file", "testdata/function-with-conflicts.yaml"}, + hasErr: true, + verify: func(t *testing.T, output string) { + assert.Contains(t, output, "conflict with existing function") + }, }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -69,10 +77,15 @@ func TestCreateFunctionCommand(t *testing.T) { buf := new(bytes.Buffer) c.SetOut(buf) + c.SetErr(buf) c.SetArgs(tt.args) err := c.Execute() - assert.NoError(t, err) + if tt.hasErr { + assert.Error(t, err) + } else { + assert.NoError(t, err) + } if tt.verify != nil { tt.verify(t, buf.String()) diff --git a/cmd/testdata/function-with-conflicts.yaml b/cmd/testdata/function-with-conflicts.yaml new file mode 100644 index 00000000..d5a8d43a --- /dev/null +++ b/cmd/testdata/function-with-conflicts.yaml @@ -0,0 +1,4 @@ +items: + - name: randEnum + render: | + {{ randInt 18 60 }} diff --git a/console/atest-ui/src/App.vue b/console/atest-ui/src/App.vue index 1652dbf9..ca861ce8 100644 --- a/console/atest-ui/src/App.vue +++ b/console/atest-ui/src/App.vue @@ -8,6 +8,7 @@ import { Guide, DataAnalysis, Help, Setting } from '@element-plus/icons-vue' +import * as ElementPlusIcons from '@element-plus/icons-vue' import { ref, watch, getCurrentInstance} from 'vue' import { API } from './views/net' import { Cache } from './views/cache' @@ -16,7 +17,6 @@ import TestingHistoryPanel from './views/TestingHistoryPanel.vue' import MockManager from './views/MockManager.vue' import StoreManager from './views/StoreManager.vue' import WelcomePage from './views/WelcomePage.vue' -import DataManager from './views/DataManager.vue' import MagicKey from './components/MagicKey.vue' import Extension from './views/Extension.vue' import { useI18n } from 'vue-i18n' @@ -152,17 +152,13 @@ API.GetMenus((menus) => { - - - - - + @@ -177,7 +173,6 @@ API.GetMenus((menus) => { - diff --git a/console/atest-ui/src/views/DataManager.vue b/console/atest-ui/src/views/DataManager.vue deleted file mode 100644 index 02a43d3b..00000000 --- a/console/atest-ui/src/views/DataManager.vue +++ /dev/null @@ -1,465 +0,0 @@ - - - - - diff --git a/console/atest-ui/src/views/Extension.vue b/console/atest-ui/src/views/Extension.vue index 95a23b5a..e8287a57 100644 --- a/console/atest-ui/src/views/Extension.vue +++ b/console/atest-ui/src/views/Extension.vue @@ -1,16 +1,16 @@ diff --git a/console/atest-ui/src/views/StoreManager.vue b/console/atest-ui/src/views/StoreManager.vue index 59c91498..6e3715ba 100644 --- a/console/atest-ui/src/views/StoreManager.vue +++ b/console/atest-ui/src/views/StoreManager.vue @@ -130,8 +130,8 @@ const submitForm = async (formEl: FormInstance | undefined) => { }) } -watch(() => storeForm.kind.name, (name) => { - const ext = SupportedExtension(name) +watch(() => storeForm.kind.name, async (name) => { + const ext = await SupportedExtension(name) if (ext) { storeExtLink.value = ext.link let pro = storeForm.properties.slice() @@ -211,6 +211,10 @@ function updateKeys() { } const storeExtLink = ref('') +const extensions = ref([]) +SupportedExtensions().then(e => { + extensions.value = e +})