Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ BUILD_PATH=$(patsubst %/,%,$(dir $(MKFILE_PATH)))/build/working_dir
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
GO_BUILD=go build -buildmode=plugin -trimpath -gcflags="all=-N -l"

PLUGINS_CMD_ROOT=./cmd/plugin
PLUGINS_DIR=$(shell find ${PLUGINS_CMD_ROOT} -name "main.go" -exec dirname {} \;)
PLUGINS_NAME=$(notdir ${PLUGINS_DIR})
PLUGIN_SUFFIX=${GOOS}-${GOARCH}_${VERSION}

DTM_INTER_PKG=github.com/devstream-io/devstream/internal/pkg
GO_LDFLAGS += -X '$(DTM_INTER_PKG)/version.Version=$(VERSION)' \
-X '$(DTM_INTER_PKG)/list.PluginsName=$(PLUGINS_NAME)'

ifeq ($(GOOS),linux)
MD5SUM=md5sum
else
Expand All @@ -31,7 +34,7 @@ clean: ## Remove dtm and plugins. It's best to run a "clean" before "build".

.PHONY: build-core
build-core: fmt vet mod-tidy ## Build dtm core only, without plugins, locally.
go build -trimpath -gcflags="all=-N -l" -ldflags "-X github.com/devstream-io/devstream/internal/pkg/version.Version=${VERSION}" -o dtm-${GOOS}-${GOARCH} ./cmd/devstream/
go build -trimpath -gcflags="all=-N -l" -ldflags "$(GO_LDFLAGS)" -o dtm-${GOOS}-${GOARCH} ./cmd/devstream/
rm -f dtm
cp dtm-${GOOS}-${GOARCH} dtm

Expand Down
51 changes: 51 additions & 0 deletions cmd/devstream/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package main

import (
"fmt"

"github.com/spf13/cobra"

"github.com/devstream-io/devstream/internal/pkg/list"
"github.com/devstream-io/devstream/pkg/util/log"
)

var listCMD = &cobra.Command{
Use: "list",
Short: "This command lists all of the plugins",
Long: `This command lists all of the plugins.
eg.
- dtm list plugins`,
Run: listCMDFunc,
}

func listCMDFunc(cmd *cobra.Command, args []string) {
if err := validateListCMDArgs(args); err != nil {
log.Fatal(err)
}

listAction := list.Action(args[0])
log.Debugf("The list action is: %s.", listAction)
if err := list.ExecuteAction(listAction); err != nil {
log.Fatal(err)
}
}

func validateListCMDArgs(args []string) error {
// "plugins"/ maybe it will be "core" in future.
if len(args) != 1 {
return fmt.Errorf("got illegal args count (expect 1, got %d). "+
"See `help` command for more info", len(args))
}
listAction := list.Action(args[0])
if !list.IsValideAction(listAction) {
return fmt.Errorf("invalide Develop Action")
}
return nil
}

// TODO Use `--filter=someone` (can support regex) to filter plugins on feature,
// TODO Use `--group=somegroup` to filter the specified groups on feature
// func init() {
// developCMD.PersistentFlags().StringVarP(&filter, "filter", "f", "", "filter plugins; support regex ")
// developCMD.PersistentFlags().StringVarP(&group, "group", "g", "", "filter the specified groups; support regex")
// }
1 change: 1 addition & 0 deletions cmd/devstream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func init() {
rootCMD.AddCommand(destroyCMD)
rootCMD.AddCommand(verifyCMD)
rootCMD.AddCommand(developCMD)
rootCMD.AddCommand(listCMD)
}

func initConfig() {
Expand Down
38 changes: 38 additions & 0 deletions internal/pkg/list/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package list

import (
"github.com/devstream-io/devstream/internal/pkg/list/plugins"
"github.com/devstream-io/devstream/pkg/util/log"
)

// list is the version of DevStream.
// Assign the value when building with the -X parameter. Example:
// -X github.com/devstream-io/devstream/internal/pkg/list.PluginsName=${PLUGINS_NAME}
// See the Makefile for more info.

var PluginsName string

type Action string

const (
ActionListPlugin Action = "plugins"
)

var ActionSet = map[Action]struct{}{
ActionListPlugin: {},
}

func IsValideAction(action Action) bool {
_, ok := ActionSet[action]
return ok
}

func ExecuteAction(action Action) error {
switch action {
case ActionListPlugin:
log.Debugf("Action: %s.", ActionListPlugin)
return plugins.List(PluginsName)
default:
panic("This should be never happen!")
}
}
17 changes: 17 additions & 0 deletions internal/pkg/list/plugins/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package plugins

import (
"fmt"
"strings"
// "github.com/spf13/viper"
// "github.com/devstream-io/devstream/pkg/util/log"
)

// List all of plugins name
func List(PluginsName string) error {
listPluginsName := strings.Fields(PluginsName)
for _, pluginName := range listPluginsName {
fmt.Println(pluginName)
}
return nil
}