Skip to content

Commit

Permalink
Merge pull request #2137 from tukobadnyanoba/add-ports-and-sync-listing
Browse files Browse the repository at this point in the history
Add ports and sync listing
  • Loading branch information
FabianKramm authored Jun 28, 2022
2 parents 3bcf870 + 0400b51 commit 7880d00
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 78 deletions.
68 changes: 26 additions & 42 deletions cmd/list/ports.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package list

import (
"context"
"github.com/loft-sh/devspace/cmd/flags"
"github.com/loft-sh/devspace/pkg/util/factory"
"github.com/loft-sh/devspace/pkg/util/log"
"github.com/loft-sh/devspace/pkg/util/message"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -33,9 +37,9 @@ Lists the port forwarding configurations

// RunListPort runs the list port command logic
func (cmd *portsCmd) RunListPort(f factory.Factory, cobraCmd *cobra.Command, args []string) error {
/*logger := f.GetLog()
logger := f.GetLog()
// Set config root
configLoader := f.NewConfigLoader(cmd.ConfigPath)
configLoader, _ := f.NewConfigLoader(cmd.ConfigPath)
configExists, err := configLoader.SetDevSpaceRoot(logger)
if err != nil {
return err
Expand All @@ -44,60 +48,40 @@ func (cmd *portsCmd) RunListPort(f factory.Factory, cobraCmd *cobra.Command, arg
return errors.New(message.ConfigNotFound)
}

configInterface, err := configLoader.Load(cmd.ToConfigOptions(logger), logger)
configInterface, err := configLoader.Load(context.TODO(), nil, cmd.ToConfigOptions(), logger)
if err != nil {
return err
}

config := configInterface.Config()
if config.Dev.Ports == nil || len(config.Dev.Ports) == 0 {
logger.Info("No ports are forwarded.\n")
return nil
}
headerColumnNames := []string{
"ImageSelector",
"LabelSelector",
"Ports (Local:Remote)",
}
portForwards := make([][]string, 0, len(config.Dev.Ports))
// Transform values into string arrays
for _, value := range config.Dev.Ports {
portForwards := make([][]string, 0)
for _, dev := range config.Dev {
if dev.Ports == nil || len(dev.Ports) == 0 {
logger.Info("No ports are forwarded.\n")
return nil
}
selector := ""
for k, v := range value.LabelSelector {
for k, v := range dev.LabelSelector {
if len(selector) > 0 {
selector += ", "
}
selector += k + "=" + v
}
portMappings := ""
if value.PortMappings != nil {
for _, v := range value.PortMappings {
if len(portMappings) > 0 {
portMappings += ", "
}
remotePort := *v.LocalPort
if v.RemotePort != nil {
remotePort = *v.RemotePort
}
portMappings += strconv.Itoa(*v.LocalPort) + ":" + strconv.Itoa(remotePort)
}
// Transform values into string arrays
for _, value := range dev.Ports {
portForwards = append(portForwards, []string{
dev.ImageSelector,
selector,
value.Port,
})
}
portForwards = append(portForwards, []string{
value.ImageSelector,
selector,
portMappings,
})
}

headerColumnNames := []string{
"ImageSelector",
"LabelSelector",
"Ports (Local:Remote)",
}
log.PrintTable(logger, headerColumnNames, portForwards)
return nil*/
return nil
}
69 changes: 33 additions & 36 deletions cmd/list/sync.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package list

import (
"context"
"github.com/loft-sh/devspace/cmd/flags"
"github.com/loft-sh/devspace/pkg/util/factory"
"github.com/loft-sh/devspace/pkg/util/log"
"github.com/loft-sh/devspace/pkg/util/message"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -33,9 +37,9 @@ Lists the sync configuration

// RunListSync runs the list sync command logic
func (cmd *syncCmd) RunListSync(f factory.Factory, cobraCmd *cobra.Command, args []string) error {
/*logger := f.GetLog()
logger := f.GetLog()
// Set config root
configLoader := f.NewConfigLoader(cmd.ConfigPath)
configLoader, _ := f.NewConfigLoader(cmd.ConfigPath)
configExists, err := configLoader.SetDevSpaceRoot(logger)
if err != nil {
return err
Expand All @@ -44,58 +48,51 @@ func (cmd *syncCmd) RunListSync(f factory.Factory, cobraCmd *cobra.Command, args
return errors.New(message.ConfigNotFound)
}

configInterface, err := configLoader.Load(cmd.ToConfigOptions(logger), logger)
configInterface, err := configLoader.Load(context.TODO(), nil, cmd.ToConfigOptions(), logger)
if err != nil {
return err
}

config := configInterface.Config()
if config.Dev.Sync == nil || len(config.Dev.Sync) == 0 {
logger.Info("No sync paths are configured. Run `devspace add sync` to add new sync path\n")
return nil
}
headerColumnNames := []string{
"Label Selector",
"Local Path",
"Container Path",
"Excluded Paths",
}
syncPaths := make([][]string, 0)

syncPaths := make([][]string, 0, len(config.Dev.Sync))
// Transform values into string arrays
for _, value := range config.Dev.Sync {
for _, dev := range config.Dev {
if dev.Sync == nil || len(dev.Sync) == 0 {
logger.Info("No sync paths are configured.")
return nil
}
selector := ""
for k, v := range value.LabelSelector {
for k, v := range dev.LabelSelector {
if len(selector) > 0 {
selector += ", "
}
selector += k + "=" + v
}
excludedPaths := ""
if value.ExcludePaths != nil {
for _, v := range value.ExcludePaths {
if len(excludedPaths) > 0 {
excludedPaths += ", "
// Transform values into string arrays
for _, value := range dev.Sync {
excludedPaths := ""
if value.ExcludePaths != nil {
for _, v := range value.ExcludePaths {
if len(excludedPaths) > 0 {
excludedPaths += ", "
}
excludedPaths += v
}
excludedPaths += v
}
syncPaths = append(syncPaths, []string{
selector,
value.Path,
excludedPaths,
})
}
}

syncPaths = append(syncPaths, []string{
selector,
value.LocalSubPath,
value.ContainerPath,
excludedPaths,
})
headerColumnNames := []string{
"Label Selector",
"Path (Local:Container)",
"Excluded Paths",
}

log.PrintTable(logger, headerColumnNames, syncPaths)
return nil*/
return nil
}

0 comments on commit 7880d00

Please sign in to comment.