Skip to content

Commit 7880d00

Browse files
authored
Merge pull request #2137 from tukobadnyanoba/add-ports-and-sync-listing
Add ports and sync listing
2 parents 3bcf870 + 0400b51 commit 7880d00

2 files changed

Lines changed: 59 additions & 78 deletions

File tree

cmd/list/ports.go

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package list
22

33
import (
4+
"context"
45
"github.com/loft-sh/devspace/cmd/flags"
56
"github.com/loft-sh/devspace/pkg/util/factory"
7+
"github.com/loft-sh/devspace/pkg/util/log"
8+
"github.com/loft-sh/devspace/pkg/util/message"
9+
"github.com/pkg/errors"
610
"github.com/spf13/cobra"
711
)
812

@@ -33,9 +37,9 @@ Lists the port forwarding configurations
3337

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

47-
configInterface, err := configLoader.Load(cmd.ToConfigOptions(logger), logger)
51+
configInterface, err := configLoader.Load(context.TODO(), nil, cmd.ToConfigOptions(), logger)
4852
if err != nil {
4953
return err
5054
}
5155

5256
config := configInterface.Config()
53-
if config.Dev.Ports == nil || len(config.Dev.Ports) == 0 {
54-
logger.Info("No ports are forwarded.\n")
55-
return nil
56-
}
57-
58-
headerColumnNames := []string{
59-
"ImageSelector",
60-
"LabelSelector",
61-
"Ports (Local:Remote)",
62-
}
63-
64-
portForwards := make([][]string, 0, len(config.Dev.Ports))
65-
66-
// Transform values into string arrays
67-
for _, value := range config.Dev.Ports {
57+
portForwards := make([][]string, 0)
58+
for _, dev := range config.Dev {
59+
if dev.Ports == nil || len(dev.Ports) == 0 {
60+
logger.Info("No ports are forwarded.\n")
61+
return nil
62+
}
6863
selector := ""
69-
for k, v := range value.LabelSelector {
64+
for k, v := range dev.LabelSelector {
7065
if len(selector) > 0 {
7166
selector += ", "
7267
}
73-
7468
selector += k + "=" + v
7569
}
76-
77-
portMappings := ""
78-
if value.PortMappings != nil {
79-
for _, v := range value.PortMappings {
80-
if len(portMappings) > 0 {
81-
portMappings += ", "
82-
}
83-
84-
remotePort := *v.LocalPort
85-
if v.RemotePort != nil {
86-
remotePort = *v.RemotePort
87-
}
88-
89-
portMappings += strconv.Itoa(*v.LocalPort) + ":" + strconv.Itoa(remotePort)
90-
}
70+
// Transform values into string arrays
71+
for _, value := range dev.Ports {
72+
portForwards = append(portForwards, []string{
73+
dev.ImageSelector,
74+
selector,
75+
value.Port,
76+
})
9177
}
92-
93-
portForwards = append(portForwards, []string{
94-
value.ImageSelector,
95-
selector,
96-
portMappings,
97-
})
9878
}
9979

80+
headerColumnNames := []string{
81+
"ImageSelector",
82+
"LabelSelector",
83+
"Ports (Local:Remote)",
84+
}
10085
log.PrintTable(logger, headerColumnNames, portForwards)
101-
return nil*/
10286
return nil
10387
}

cmd/list/sync.go

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package list
22

33
import (
4+
"context"
45
"github.com/loft-sh/devspace/cmd/flags"
56
"github.com/loft-sh/devspace/pkg/util/factory"
7+
"github.com/loft-sh/devspace/pkg/util/log"
8+
"github.com/loft-sh/devspace/pkg/util/message"
9+
"github.com/pkg/errors"
610
"github.com/spf13/cobra"
711
)
812

@@ -33,9 +37,9 @@ Lists the sync configuration
3337

3438
// RunListSync runs the list sync command logic
3539
func (cmd *syncCmd) RunListSync(f factory.Factory, cobraCmd *cobra.Command, args []string) error {
36-
/*logger := f.GetLog()
40+
logger := f.GetLog()
3741
// Set config root
38-
configLoader := f.NewConfigLoader(cmd.ConfigPath)
42+
configLoader, _ := f.NewConfigLoader(cmd.ConfigPath)
3943
configExists, err := configLoader.SetDevSpaceRoot(logger)
4044
if err != nil {
4145
return err
@@ -44,58 +48,51 @@ func (cmd *syncCmd) RunListSync(f factory.Factory, cobraCmd *cobra.Command, args
4448
return errors.New(message.ConfigNotFound)
4549
}
4650

47-
configInterface, err := configLoader.Load(cmd.ToConfigOptions(logger), logger)
51+
configInterface, err := configLoader.Load(context.TODO(), nil, cmd.ToConfigOptions(), logger)
4852
if err != nil {
4953
return err
5054
}
5155

5256
config := configInterface.Config()
53-
if config.Dev.Sync == nil || len(config.Dev.Sync) == 0 {
54-
logger.Info("No sync paths are configured. Run `devspace add sync` to add new sync path\n")
55-
return nil
56-
}
57-
58-
headerColumnNames := []string{
59-
"Label Selector",
60-
"Local Path",
61-
"Container Path",
62-
"Excluded Paths",
63-
}
57+
syncPaths := make([][]string, 0)
6458

65-
syncPaths := make([][]string, 0, len(config.Dev.Sync))
66-
67-
// Transform values into string arrays
68-
for _, value := range config.Dev.Sync {
59+
for _, dev := range config.Dev {
60+
if dev.Sync == nil || len(dev.Sync) == 0 {
61+
logger.Info("No sync paths are configured.")
62+
return nil
63+
}
6964
selector := ""
70-
71-
for k, v := range value.LabelSelector {
65+
for k, v := range dev.LabelSelector {
7266
if len(selector) > 0 {
7367
selector += ", "
7468
}
75-
7669
selector += k + "=" + v
7770
}
78-
excludedPaths := ""
79-
80-
if value.ExcludePaths != nil {
81-
for _, v := range value.ExcludePaths {
82-
if len(excludedPaths) > 0 {
83-
excludedPaths += ", "
71+
// Transform values into string arrays
72+
for _, value := range dev.Sync {
73+
excludedPaths := ""
74+
if value.ExcludePaths != nil {
75+
for _, v := range value.ExcludePaths {
76+
if len(excludedPaths) > 0 {
77+
excludedPaths += ", "
78+
}
79+
excludedPaths += v
8480
}
85-
86-
excludedPaths += v
8781
}
82+
syncPaths = append(syncPaths, []string{
83+
selector,
84+
value.Path,
85+
excludedPaths,
86+
})
8887
}
88+
}
8989

90-
syncPaths = append(syncPaths, []string{
91-
selector,
92-
value.LocalSubPath,
93-
value.ContainerPath,
94-
excludedPaths,
95-
})
90+
headerColumnNames := []string{
91+
"Label Selector",
92+
"Path (Local:Container)",
93+
"Excluded Paths",
9694
}
9795

9896
log.PrintTable(logger, headerColumnNames, syncPaths)
99-
return nil*/
10097
return nil
10198
}

0 commit comments

Comments
 (0)