Skip to content

Commit 34c5f35

Browse files
authored
[plugins] fix info for packages with process-compose services (#1689)
## Summary We were relying on the package already being installed and in virtenv. This change ensures it works when not installed as well. ## How was it tested? `devbox info php`
1 parent 862bebe commit 34c5f35

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

internal/plugin/info.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/pkg/errors"
1414
"github.com/samber/lo"
1515
"go.jetpack.io/devbox/internal/devpkg"
16+
"go.jetpack.io/devbox/internal/services"
1617
)
1718

1819
func Readme(ctx context.Context,
@@ -39,7 +40,7 @@ func Readme(ctx context.Context,
3940
return "", err
4041
}
4142

42-
if err = printServices(cfg, buf, markdown); err != nil {
43+
if err = printServices(cfg, pkg, buf, markdown); err != nil {
4344
return "", err
4445
}
4546

@@ -72,17 +73,25 @@ func printReadme(cfg *config, w io.Writer, markdown bool) error {
7273
return errors.WithStack(err)
7374
}
7475

75-
func printServices(cfg *config, w io.Writer, markdown bool) error {
76-
svcs, err := cfg.Services()
76+
func printServices(cfg *config, pkg *devpkg.Package, w io.Writer, markdown bool) error {
77+
_, contentPath := cfg.ProcessComposeYaml()
78+
if contentPath == "" {
79+
return nil
80+
}
81+
content, err := pkg.FileContent(contentPath)
82+
if err != nil {
83+
return errors.WithStack(err)
84+
}
85+
serviceNames, err := services.NamesFromProcessCompose(content)
7786
if err != nil {
7887
return errors.WithStack(err)
7988
}
80-
if len(svcs) == 0 {
89+
if len(serviceNames) == 0 {
8190
return nil
8291
}
8392
services := ""
84-
for _, service := range svcs {
85-
services += fmt.Sprintf("* %[1]s\n", service.Name)
93+
for _, serviceName := range serviceNames {
94+
services += fmt.Sprintf("* %[1]s\n", serviceName)
8695
}
8796

8897
_, err = fmt.Fprintf(

internal/plugin/plugin.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ type config struct {
5050
} `json:"shell,omitempty"`
5151
}
5252

53-
func (c *config) ProcessComposeYaml() (string, bool) {
54-
for file := range c.CreateFiles {
53+
func (c *config) ProcessComposeYaml() (string, string) {
54+
for file, contentPath := range c.CreateFiles {
5555
if strings.HasSuffix(file, "process-compose.yaml") || strings.HasSuffix(file, "process-compose.yml") {
56-
return file, true
56+
return file, contentPath
5757
}
5858
}
59-
return "", false
59+
return "", ""
6060
}
6161

6262
func (c *config) Services() (services.Services, error) {
63-
if file, ok := c.ProcessComposeYaml(); ok {
63+
if file, _ := c.ProcessComposeYaml(); file != "" {
6464
return services.FromProcessCompose(file)
6565
}
6666
return nil, nil

internal/services/config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/f1bonacc1/process-compose/src/types"
1212
"github.com/pkg/errors"
13+
"gopkg.in/yaml.v3"
1314

1415
"go.jetpack.io/devbox/internal/cuecfg"
1516
)
@@ -47,6 +48,18 @@ func FromProcessCompose(path string) (Services, error) {
4748
return services, nil
4849
}
4950

51+
func NamesFromProcessCompose(content []byte) ([]string, error) {
52+
var processCompose types.Project
53+
if err := yaml.Unmarshal(content, &processCompose); err != nil {
54+
return nil, err
55+
}
56+
names := []string{}
57+
for name := range processCompose.Processes {
58+
names = append(names, name)
59+
}
60+
return names, nil
61+
}
62+
5063
func lookupProcessCompose(projectDir, path string) string {
5164
if path == "" {
5265
path = projectDir

0 commit comments

Comments
 (0)