Skip to content

Commit

Permalink
Merge pull request #1119 from devstream-io/main
Browse files Browse the repository at this point in the history
Prepare to release v0.9.1
  • Loading branch information
daniel-hutao authored Sep 23, 2022
2 parents a80c4b9 + e042b72 commit 45c1ea0
Show file tree
Hide file tree
Showing 88 changed files with 2,471 additions and 1,214 deletions.
1 change: 1 addition & 0 deletions cmd/devstream/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func destroyCMDFunc(cmd *cobra.Command, args []string) {
func init() {
destroyCMD.Flags().BoolVarP(&isForceDestroy, "force", "", false, "force destroy by config")
destroyCMD.Flags().StringVarP(&configFile, configFlagName, "f", "config.yaml", "config file")
destroyCMD.Flags().StringVarP(&pluginDir, pluginDirFlagName, "d", "", "plugins directory")
destroyCMD.Flags().BoolVarP(&continueDirectly, "yes", "y", false, "destroy directly without confirmation")

completion.FlagFilenameCompletion(destroyCMD, configFlagName)
Expand Down
5 changes: 3 additions & 2 deletions cmd/devstream/develop.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func init() {
developCMD.AddCommand(developCreatePluginCMD)
developCMD.AddCommand(developValidatePluginCMD)

developCreatePluginCMD.PersistentFlags().StringVarP(&name, "name", "n", "", "specify name with the new plugin")
developValidatePluginCMD.PersistentFlags().StringVarP(&name, "name", "n", "", "specify name with the new plugin")
developCreatePluginCMD.PersistentFlags().StringVarP(&name, "name", "n", "", "specify name of the plugin to be created")

developValidatePluginCMD.PersistentFlags().StringVarP(&name, "name", "n", "", "specify name of the plugin to be validated")
developValidatePluginCMD.PersistentFlags().BoolVarP(&all, "all", "a", false, "validate all plugins")
}
107 changes: 96 additions & 11 deletions cmd/devstream/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package main

import (
"fmt"
"runtime"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/devstream-io/devstream/cmd/devstream/list"
"github.com/devstream-io/devstream/internal/pkg/completion"
"github.com/devstream-io/devstream/internal/pkg/configmanager"
"github.com/devstream-io/devstream/internal/pkg/pluginmanager"
Expand All @@ -20,35 +24,116 @@ var initCMD = &cobra.Command{
Run: initCMDFunc,
}

var (
downloadOnly bool // download plugins only, from command line flags
downloadAll bool // download all plugins
pluginsToDownload []string // download specific plugins
initOS string // download plugins for specific os
initArch string // download plugins for specific arch
)

func initCMDFunc(_ *cobra.Command, _ []string) {
if version.Dev {
log.Fatalf("Dev version plugins can't be downloaded from the remote plugin repo; please run `make build-plugin.PLUGIN_NAME` to build them locally.")
}

var (
realPluginDir string
tools []configmanager.Tool
err error
)

if downloadOnly {
// download plugins from flags
tools, realPluginDir, err = GetPluginsAndPluginDirFromFlags()
} else {
// download plugins according to the config file
tools, realPluginDir, err = GetPluginsAndPluginDirFromConfig()
}

if err != nil {
log.Fatal(err)
}

if err := pluginmanager.DownloadPlugins(tools, realPluginDir, initOS, initArch); err != nil {
log.Fatal(err)
}

fmt.Println()
log.Success("Initialize finished.")
}

func GetPluginsAndPluginDirFromConfig() (tools []configmanager.Tool, pluginDir string, err error) {
cfg, err := configmanager.NewManager(configFile).LoadConfig()
if err != nil {
log.Errorf("Error: %s.", err)
return
return nil, "", err
}

// combine plugin dir from config file and flag
if err := file.SetPluginDir(cfg.PluginDir); err != nil {
log.Errorf("Error: %s.", err)
return nil, "", err
}

if version.Dev {
log.Errorf("Dev version plugins can't be downloaded from the remote plugin repo; please run `make build-plugin.PLUGIN_NAME` to build them locally.")
return
return cfg.Tools, viper.GetString(pluginDirFlagName), nil
}

func GetPluginsAndPluginDirFromFlags() (tools []configmanager.Tool, pluginDir string, err error) {
// 1. get plugins from flags
var pluginsName []string
if downloadAll {
// download all plugins
pluginsName = list.PluginsNameSlice()
} else {
// download specific plugins
for _, pluginName := range pluginsToDownload {
if p := strings.ToLower(strings.TrimSpace(pluginName)); p != "" {
pluginsName = append(pluginsName, p)
}
}
// check if plugins to download are supported by dtm
for _, plugin := range pluginsName {
if _, ok := list.PluginNamesMap()[plugin]; !ok {
return nil, "", fmt.Errorf("Plugin %s is not supported by dtm", plugin)
}
}
}

if err = pluginmanager.DownloadPlugins(cfg); err != nil {
log.Errorf("Error: %s.", err)
return
if len(pluginsName) == 0 {
log.Errorf("Please use --plugins to specify plugins to download or use --all to download all plugins.")
}
log.Debugf("plugins to download: %v", pluginsName)

fmt.Println()
log.Success("Initialize finished.")
if initOS == "" || initArch == "" {
return nil, "", fmt.Errorf("Once you use the --all flag, you must specify the --os and --arch flags")
}

log.Infof("Plugins to download: %v", pluginsName)

// build the plugin list
for _, pluginName := range pluginsName {
tools = append(tools, configmanager.Tool{Name: pluginName})
}

// 2. handle plugin dir
if err := file.SetPluginDir(""); err != nil {
return nil, "", err
}

return tools, viper.GetString(pluginDirFlagName), nil
}

func init() {
// flags for init from config file
initCMD.Flags().StringVarP(&configFile, configFlagName, "f", "config.yaml", "config file")
initCMD.Flags().StringVarP(&pluginDir, pluginDirFlagName, "d", "", "plugins directory")

// downloading specific plugins from flags
initCMD.Flags().BoolVar(&downloadOnly, "download-only", false, "download plugins only")
initCMD.Flags().StringSliceVarP(&pluginsToDownload, "plugins", "p", []string{}, "the plugins to be downloaded")
initCMD.Flags().BoolVarP(&downloadAll, "all", "a", false, "download all plugins")
initCMD.Flags().StringVar(&initOS, "os", runtime.GOOS, "download plugins for specific os")
initCMD.Flags().StringVar(&initArch, "arch", runtime.GOARCH, "download plugins for specific arch")

completion.FlagFilenameCompletion(initCMD, configFlagName)
completion.FlagDirnameCompletion(initCMD, pluginDirFlagName)
}
4 changes: 1 addition & 3 deletions cmd/devstream/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ var PluginsName string

// List all plugins name
func List(pluginFilter string) {
listPluginsName := strings.Fields(PluginsName)
r, _ := regexp.Compile(pluginFilter)
sort.Strings(listPluginsName)
for _, pluginName := range listPluginsName {
for _, pluginName := range PluginsNameSlice() {
if r.Match([]byte(pluginName)) {
fmt.Println(pluginName)
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/devstream/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var template string

var showCMD = &cobra.Command{
Use: "show",
Short: "Show is used to print some useful information",
Short: "Show is used to print plugins' configuration templates or status.",
}

var showConfigCMD = &cobra.Command{
Expand All @@ -25,7 +25,8 @@ var showConfigCMD = &cobra.Command{
Long: `Show config is used for showing plugins' template configuration information.
Examples:
dtm show config --plugin=A-PLUGIN-NAME,
dtm show config --template=quickstart`,
dtm show config --template=quickstart,
dtm show config --template=gitops`,
Run: showConfigCMDFunc,
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/devstream/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ func upgradeCMDFunc(cmd *cobra.Command, args []string) {
}

func init() {
upgradeCMD.Flags().BoolVarP(&continueDirectly, "yes", "y", false, "apply directly without confirmation")
upgradeCMD.Flags().BoolVarP(&continueDirectly, "yes", "y", false, "upgrade directly without confirmation")
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
package main

import (
"github.com/devstream-io/devstream/internal/pkg/plugin/jenkinspipelinekubernetes"
"github.com/devstream-io/devstream/internal/pkg/plugin/sonarqube"
"github.com/devstream-io/devstream/pkg/util/log"
)

// NAME is the name of this DevStream plugin.
const NAME = "jenkins-pipeline-kubernetes"
const NAME = "sonarqube"

// Plugin is the type used by DevStream core. It's a string.
type Plugin string

// Create implements the create of jenkins-pipeline-kubernetes.
// Create implements the create of sonar.
func (p Plugin) Create(options map[string]interface{}) (map[string]interface{}, error) {
return jenkinspipelinekubernetes.Create(options)
return sonarqube.Create(options)
}

// Update implements the update of jenkins-pipeline-kubernetes.
// Update implements the update of sonar.
func (p Plugin) Update(options map[string]interface{}) (map[string]interface{}, error) {
return jenkinspipelinekubernetes.Update(options)
return sonarqube.Update(options)
}

// Delete implements the delete of jenkins-pipeline-kubernetes.
// Delete implements the delete of sonar.
func (p Plugin) Delete(options map[string]interface{}) (bool, error) {
return jenkinspipelinekubernetes.Delete(options)
return sonarqube.Delete(options)
}

// Read implements the read of jenkins-pipeline-kubernetes.
// Read implements the read of sonar.
func (p Plugin) Read(options map[string]interface{}) (map[string]interface{}, error) {
return jenkinspipelinekubernetes.Read(options)
return sonarqube.Read(options)
}

// DevStreamPlugin is the exported variable used by the DevStream core.
Expand Down
Loading

0 comments on commit 45c1ea0

Please sign in to comment.