Skip to content

Commit

Permalink
Infer bundle name in bundle install (#393)
Browse files Browse the repository at this point in the history
Use primary bundles to auto-infer bundle name on install command
  • Loading branch information
michaeljguarino authored Apr 7, 2023
1 parent b7805db commit 6d943fb
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 18 deletions.
42 changes: 33 additions & 9 deletions cmd/plural/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (p *Plural) bundleCommands() []cli.Command {
Usage: "re-enter the configuration for this bundle",
},
},
Action: tracked(latestVersion(rooted(requireArgs(p.bundleInstall, []string{"repo", "bundle-name"}))), "bundle.install"),
Action: tracked(latestVersion(rooted(p.bundleInstall)), "bundle.install"),
},
}
}
Expand Down Expand Up @@ -63,15 +63,9 @@ func (p *Plural) stackCommands() []cli.Command {
}

func (p *Plural) bundleList(c *cli.Context) error {
man, err := manifest.FetchProject()
repo := c.Args().Get(0)
prov := ""
if err == nil {
prov = strings.ToUpper(man.Provider)
}

p.InitPluralClient()
recipes, err := p.ListRecipes(repo, prov)
recipes, err := p.listRecipes(repo)
if err != nil {
return api.GetErrorResponse(err, "ListRecipes")
}
Expand All @@ -85,7 +79,26 @@ func (p *Plural) bundleList(c *cli.Context) error {
func (p *Plural) bundleInstall(c *cli.Context) (err error) {
args := c.Args()
p.InitPluralClient()
err = bundle.Install(p.Client, args.Get(0), args.Get(1), c.Bool("refresh"))
repo := args.Get(0)
if repo == "" {
return fmt.Errorf("REPO argument required, try running `plural bundle install REPO` for the app you want to install")
}

bdl := args.Get(1)
if bdl == "" {
recipes, err := p.listRecipes(args.Get(0))
if err != nil {
return err
}
for _, recipe := range recipes {
if recipe.Primary {
bdl = recipe.Name
break
}
}
}

err = bundle.Install(p.Client, repo, bdl, c.Bool("refresh"))
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")
return
}
Expand Down Expand Up @@ -115,3 +128,14 @@ func (p *Plural) stackList(c *cli.Context) (err error) {
return []string{s.Name, s.Description, fmt.Sprintf("%v", s.Featured)}, nil
})
}

func (p *Plural) listRecipes(repo string) (res []*api.Recipe, err error) {
man, err := manifest.FetchProject()
prov := ""
if err == nil {
prov = strings.ToUpper(man.Provider)
}

res, err = p.ListRecipes(repo, prov)
return
}
4 changes: 2 additions & 2 deletions cmd/plural/plural.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (p *Plural) getCommands() []cli.Command {
Name: "deploy",
Aliases: []string{"d"},
Usage: "Deploys the current workspace. This command will first sniff out git diffs in workspaces, topsort them, then apply all changes.",
ArgsUsage: "WKSPACE",
ArgsUsage: "Workspace",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "silence",
Expand Down Expand Up @@ -297,7 +297,7 @@ func (p *Plural) getCommands() []cli.Command {
Name: "repair",
Usage: "commits any new encrypted changes in your local workspace automatically",
Action: latestVersion(handleRepair),
Category: "WORKSPACE",
Category: "Workspace",
},
{
Name: "serve",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ require (
github.com/olekukonko/tablewriter v0.0.5
github.com/packethost/packngo v0.29.0
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/pluralsh/gqlclient v1.3.14
github.com/pluralsh/gqlclient v1.3.15
github.com/pluralsh/plural-operator v0.5.3
github.com/pluralsh/polly v0.1.1
github.com/rodaine/hclencoder v0.0.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,8 @@ github.com/pluralsh/controller-reconcile-helper v0.0.4 h1:1o+7qYSyoeqKFjx+WgQTxD
github.com/pluralsh/controller-reconcile-helper v0.0.4/go.mod h1:AfY0gtteD6veBjmB6jiRx/aR4yevEf6K0M13/pGan/s=
github.com/pluralsh/gqlclient v1.3.14 h1:MX3odnIfPSYT9PysegKkC31w/Vn8PZhrT/rZXZck/yU=
github.com/pluralsh/gqlclient v1.3.14/go.mod h1:z1qHnvPeqIN/a+5OzFs40e6HI6tDxzh1+yJuEpvqGy4=
github.com/pluralsh/gqlclient v1.3.15 h1:QA6VEMDxeG0/e+qXvr7xgorHl45o4/Qg9CwsPyVn2gE=
github.com/pluralsh/gqlclient v1.3.15/go.mod h1:z1qHnvPeqIN/a+5OzFs40e6HI6tDxzh1+yJuEpvqGy4=
github.com/pluralsh/oauth v0.9.2 h1:tM9hBK4tCnJUeCOgX0ctxBBCS3hiCDPoxkJLODtedmQ=
github.com/pluralsh/oauth v0.9.2/go.mod h1:aTUw/75rzcsbvW+/TLvWtHVDXFIdtFrDtUncOq9vHyM=
github.com/pluralsh/plural-operator v0.5.3 h1:GaPL3LgimfzKZNHt7zXzqYZpb0hgyW9noHYnkA+rqNs=
Expand Down
1 change: 1 addition & 0 deletions pkg/api/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ type Recipe struct {
Name string
Provider string
Description string
Primary bool
Restricted bool
Tests []*RecipeTest
Repository *Repository
Expand Down
11 changes: 5 additions & 6 deletions pkg/api/recipes.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ func (client *client) GetRecipe(repo, name string) (*Recipe, error) {
r := &Recipe{
Id: resp.Recipe.ID,
Name: resp.Recipe.Name,
Primary: resp.Recipe.Primary != nil && *resp.Recipe.Primary,
Restricted: resp.Recipe.Restricted != nil && *resp.Recipe.Restricted,
Provider: string(*resp.Recipe.Provider),
Description: utils.ConvertStringPointer(resp.Recipe.Description),
Tests: []*RecipeTest{},
Expand All @@ -123,9 +125,6 @@ func (client *client) GetRecipe(repo, name string) (*Recipe, error) {
Name: resp.Recipe.Repository.Name,
}
}
if resp.Recipe.Restricted != nil {
r.Restricted = *resp.Recipe.Restricted
}

for _, dep := range resp.Recipe.RecipeDependencies {
r.RecipeDependencies = append(r.RecipeDependencies, convertRecipe(dep))
Expand Down Expand Up @@ -233,6 +232,8 @@ func convertRecipe(rcp *gqlclient.RecipeFragment) *Recipe {
r := &Recipe{
Id: rcp.ID,
Name: rcp.Name,
Primary: rcp.Primary != nil && *rcp.Primary,
Restricted: rcp.Restricted != nil && *rcp.Restricted,
Description: utils.ConvertStringPointer(rcp.Description),
Tests: []*RecipeTest{},
RecipeSections: []*RecipeSection{},
Expand All @@ -252,9 +253,7 @@ func convertRecipe(rcp *gqlclient.RecipeFragment) *Recipe {
AuthMethod: string(rcp.OidcSettings.AuthMethod),
}
}
if rcp.Restricted != nil {
r.Restricted = *rcp.Restricted
}

if rcp.Provider != nil {
provider := *rcp.Provider
r.Provider = string(provider)
Expand Down

0 comments on commit 6d943fb

Please sign in to comment.