Skip to content

Commit af08f7d

Browse files
authored
feat: add 'dbdeployer providers' CLI command (#34)
Closes #30
1 parent 42f7e7f commit af08f7d

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

cmd/providers.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/ProxySQL/dbdeployer/providers"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var providersCmd = &cobra.Command{
11+
Use: "providers",
12+
Short: "Shows available deployment providers",
13+
Long: "Lists all registered providers that can be used for sandbox deployment",
14+
Run: func(cmd *cobra.Command, args []string) {
15+
for _, name := range providers.DefaultRegistry.List() {
16+
p, _ := providers.DefaultRegistry.Get(name)
17+
ports := p.DefaultPorts()
18+
fmt.Printf("%-15s (base port: %d, ports per instance: %d)\n",
19+
name, ports.BasePort, ports.PortsPerInstance)
20+
}
21+
},
22+
}
23+
24+
func init() {
25+
rootCmd.AddCommand(providersCmd)
26+
}

cmd/single.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/ProxySQL/dbdeployer/common"
2626
"github.com/ProxySQL/dbdeployer/defaults"
2727
"github.com/ProxySQL/dbdeployer/globals"
28+
"github.com/ProxySQL/dbdeployer/providers"
2829
"github.com/ProxySQL/dbdeployer/sandbox"
2930
"github.com/pkg/errors"
3031
"github.com/spf13/cobra"
@@ -445,6 +446,15 @@ func singleSandbox(cmd *cobra.Command, args []string) {
445446
if err != nil {
446447
common.Exitf(1, "error while filling the sandbox definition: %+v", err)
447448
}
449+
// Validate version with provider
450+
// TODO: Phase 2b — determine provider from sd.Flavor instead of hardcoding "mysql"
451+
p, provErr := providers.DefaultRegistry.Get("mysql")
452+
if provErr != nil {
453+
common.Exitf(1, "provider error: %s", provErr)
454+
}
455+
if provErr = p.ValidateVersion(sd.Version); provErr != nil {
456+
common.Exitf(1, "version validation failed: %s", provErr)
457+
}
448458
// When deploying a single sandbox, we disable concurrency
449459
sd.RunConcurrently = false
450460
err = sandbox.CreateStandaloneSandbox(sd)

0 commit comments

Comments
 (0)