File tree Expand file tree Collapse file tree 3 files changed +38
-4
lines changed
internal/pkg/develop/plugin Expand file tree Collapse file tree 3 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -21,3 +21,23 @@ func List() {
21
21
fmt .Println (pluginName )
22
22
}
23
23
}
24
+
25
+ // Get plugins name in slice
26
+ func PluginsNameSlice () []string {
27
+ listPluginsName := strings .Fields (PluginsName )
28
+ sort .Strings (listPluginsName )
29
+ return listPluginsName
30
+ }
31
+
32
+ // Get plugins name in map
33
+ func PluginNamesMap () map [string ]struct {} {
34
+ mp := make (map [string ]struct {})
35
+
36
+ listPluginsName := strings .Fields (PluginsName )
37
+
38
+ for _ , pluginName := range listPluginsName {
39
+ mp [pluginName ] = struct {}{}
40
+ }
41
+
42
+ return mp
43
+ }
Original file line number Diff line number Diff line change 5
5
6
6
"github.com/spf13/viper"
7
7
8
+ "github.com/devstream-io/devstream/cmd/devstream/list"
8
9
"github.com/devstream-io/devstream/pkg/util/log"
9
10
)
10
11
@@ -19,6 +20,11 @@ func Create() error {
19
20
}
20
21
log .Debugf ("Got the name: %s." , name )
21
22
23
+ if pluginExists (name ) {
24
+ return fmt .Errorf ("Plugin name: %s is already exists" , name )
25
+ }
26
+ log .Debugf ("Got the name: %s." , name )
27
+
22
28
p := NewPlugin (name )
23
29
24
30
// 1. Render template files
@@ -40,3 +46,14 @@ func Create() error {
40
46
41
47
return nil
42
48
}
49
+
50
+ // Check whether the new name exists.
51
+ func pluginExists (name string ) bool {
52
+ pluginMp := list .PluginNamesMap ()
53
+
54
+ if _ , ok := (pluginMp )[name ]; ok {
55
+ return true
56
+ }
57
+
58
+ return false
59
+ }
Original file line number Diff line number Diff line change @@ -2,8 +2,6 @@ package plugin
2
2
3
3
import (
4
4
"fmt"
5
- "sort"
6
- "strings"
7
5
8
6
"github.com/spf13/viper"
9
7
@@ -31,8 +29,7 @@ func Validate() error {
31
29
// Validate all plugins
32
30
// calling ValidatePlugin() via all plugins name
33
31
func ValidatePlugins () error {
34
- listPluginsName := strings .Fields (list .PluginsName )
35
- sort .Strings (listPluginsName )
32
+ listPluginsName := list .PluginsNameSlice ()
36
33
37
34
for _ , pluginName := range listPluginsName {
38
35
log .Infof ("===== start validating <%s> =====" , pluginName )
You can’t perform that action at this time.
0 commit comments