Skip to content

Commit 6d943fb

Browse files
Infer bundle name in bundle install (#393)
Use primary bundles to auto-infer bundle name on install command
1 parent b7805db commit 6d943fb

6 files changed

Lines changed: 44 additions & 18 deletions

File tree

cmd/plural/bundle.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (p *Plural) bundleCommands() []cli.Command {
2929
Usage: "re-enter the configuration for this bundle",
3030
},
3131
},
32-
Action: tracked(latestVersion(rooted(requireArgs(p.bundleInstall, []string{"repo", "bundle-name"}))), "bundle.install"),
32+
Action: tracked(latestVersion(rooted(p.bundleInstall)), "bundle.install"),
3333
},
3434
}
3535
}
@@ -63,15 +63,9 @@ func (p *Plural) stackCommands() []cli.Command {
6363
}
6464

6565
func (p *Plural) bundleList(c *cli.Context) error {
66-
man, err := manifest.FetchProject()
6766
repo := c.Args().Get(0)
68-
prov := ""
69-
if err == nil {
70-
prov = strings.ToUpper(man.Provider)
71-
}
72-
7367
p.InitPluralClient()
74-
recipes, err := p.ListRecipes(repo, prov)
68+
recipes, err := p.listRecipes(repo)
7569
if err != nil {
7670
return api.GetErrorResponse(err, "ListRecipes")
7771
}
@@ -85,7 +79,26 @@ func (p *Plural) bundleList(c *cli.Context) error {
8579
func (p *Plural) bundleInstall(c *cli.Context) (err error) {
8680
args := c.Args()
8781
p.InitPluralClient()
88-
err = bundle.Install(p.Client, args.Get(0), args.Get(1), c.Bool("refresh"))
82+
repo := args.Get(0)
83+
if repo == "" {
84+
return fmt.Errorf("REPO argument required, try running `plural bundle install REPO` for the app you want to install")
85+
}
86+
87+
bdl := args.Get(1)
88+
if bdl == "" {
89+
recipes, err := p.listRecipes(args.Get(0))
90+
if err != nil {
91+
return err
92+
}
93+
for _, recipe := range recipes {
94+
if recipe.Primary {
95+
bdl = recipe.Name
96+
break
97+
}
98+
}
99+
}
100+
101+
err = bundle.Install(p.Client, repo, bdl, c.Bool("refresh"))
89102
utils.Note("To edit the configuration you've just entered, edit the context.yaml file at the root of your repo, or run with the --refresh flag\n")
90103
return
91104
}
@@ -115,3 +128,14 @@ func (p *Plural) stackList(c *cli.Context) (err error) {
115128
return []string{s.Name, s.Description, fmt.Sprintf("%v", s.Featured)}, nil
116129
})
117130
}
131+
132+
func (p *Plural) listRecipes(repo string) (res []*api.Recipe, err error) {
133+
man, err := manifest.FetchProject()
134+
prov := ""
135+
if err == nil {
136+
prov = strings.ToUpper(man.Provider)
137+
}
138+
139+
res, err = p.ListRecipes(repo, prov)
140+
return
141+
}

cmd/plural/plural.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (p *Plural) getCommands() []cli.Command {
103103
Name: "deploy",
104104
Aliases: []string{"d"},
105105
Usage: "Deploys the current workspace. This command will first sniff out git diffs in workspaces, topsort them, then apply all changes.",
106-
ArgsUsage: "WKSPACE",
106+
ArgsUsage: "Workspace",
107107
Flags: []cli.Flag{
108108
cli.BoolFlag{
109109
Name: "silence",
@@ -297,7 +297,7 @@ func (p *Plural) getCommands() []cli.Command {
297297
Name: "repair",
298298
Usage: "commits any new encrypted changes in your local workspace automatically",
299299
Action: latestVersion(handleRepair),
300-
Category: "WORKSPACE",
300+
Category: "Workspace",
301301
},
302302
{
303303
Name: "serve",

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ require (
4444
github.com/olekukonko/tablewriter v0.0.5
4545
github.com/packethost/packngo v0.29.0
4646
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
47-
github.com/pluralsh/gqlclient v1.3.14
47+
github.com/pluralsh/gqlclient v1.3.15
4848
github.com/pluralsh/plural-operator v0.5.3
4949
github.com/pluralsh/polly v0.1.1
5050
github.com/rodaine/hclencoder v0.0.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,8 @@ github.com/pluralsh/controller-reconcile-helper v0.0.4 h1:1o+7qYSyoeqKFjx+WgQTxD
901901
github.com/pluralsh/controller-reconcile-helper v0.0.4/go.mod h1:AfY0gtteD6veBjmB6jiRx/aR4yevEf6K0M13/pGan/s=
902902
github.com/pluralsh/gqlclient v1.3.14 h1:MX3odnIfPSYT9PysegKkC31w/Vn8PZhrT/rZXZck/yU=
903903
github.com/pluralsh/gqlclient v1.3.14/go.mod h1:z1qHnvPeqIN/a+5OzFs40e6HI6tDxzh1+yJuEpvqGy4=
904+
github.com/pluralsh/gqlclient v1.3.15 h1:QA6VEMDxeG0/e+qXvr7xgorHl45o4/Qg9CwsPyVn2gE=
905+
github.com/pluralsh/gqlclient v1.3.15/go.mod h1:z1qHnvPeqIN/a+5OzFs40e6HI6tDxzh1+yJuEpvqGy4=
904906
github.com/pluralsh/oauth v0.9.2 h1:tM9hBK4tCnJUeCOgX0ctxBBCS3hiCDPoxkJLODtedmQ=
905907
github.com/pluralsh/oauth v0.9.2/go.mod h1:aTUw/75rzcsbvW+/TLvWtHVDXFIdtFrDtUncOq9vHyM=
906908
github.com/pluralsh/plural-operator v0.5.3 h1:GaPL3LgimfzKZNHt7zXzqYZpb0hgyW9noHYnkA+rqNs=

pkg/api/models.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ type Recipe struct {
173173
Name string
174174
Provider string
175175
Description string
176+
Primary bool
176177
Restricted bool
177178
Tests []*RecipeTest
178179
Repository *Repository

pkg/api/recipes.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ func (client *client) GetRecipe(repo, name string) (*Recipe, error) {
100100
r := &Recipe{
101101
Id: resp.Recipe.ID,
102102
Name: resp.Recipe.Name,
103+
Primary: resp.Recipe.Primary != nil && *resp.Recipe.Primary,
104+
Restricted: resp.Recipe.Restricted != nil && *resp.Recipe.Restricted,
103105
Provider: string(*resp.Recipe.Provider),
104106
Description: utils.ConvertStringPointer(resp.Recipe.Description),
105107
Tests: []*RecipeTest{},
@@ -123,9 +125,6 @@ func (client *client) GetRecipe(repo, name string) (*Recipe, error) {
123125
Name: resp.Recipe.Repository.Name,
124126
}
125127
}
126-
if resp.Recipe.Restricted != nil {
127-
r.Restricted = *resp.Recipe.Restricted
128-
}
129128

130129
for _, dep := range resp.Recipe.RecipeDependencies {
131130
r.RecipeDependencies = append(r.RecipeDependencies, convertRecipe(dep))
@@ -233,6 +232,8 @@ func convertRecipe(rcp *gqlclient.RecipeFragment) *Recipe {
233232
r := &Recipe{
234233
Id: rcp.ID,
235234
Name: rcp.Name,
235+
Primary: rcp.Primary != nil && *rcp.Primary,
236+
Restricted: rcp.Restricted != nil && *rcp.Restricted,
236237
Description: utils.ConvertStringPointer(rcp.Description),
237238
Tests: []*RecipeTest{},
238239
RecipeSections: []*RecipeSection{},
@@ -252,9 +253,7 @@ func convertRecipe(rcp *gqlclient.RecipeFragment) *Recipe {
252253
AuthMethod: string(rcp.OidcSettings.AuthMethod),
253254
}
254255
}
255-
if rcp.Restricted != nil {
256-
r.Restricted = *rcp.Restricted
257-
}
256+
258257
if rcp.Provider != nil {
259258
provider := *rcp.Provider
260259
r.Provider = string(provider)

0 commit comments

Comments
 (0)