package main import ( "context" "go.jolheiser.com/vanity/sdk" "github.com/AlecAivazis/survey/v2" "github.com/rs/zerolog/log" ) func update(token, server *string) func(context.Context, []string) error { return func(ctx context.Context, args []string) error { pkgs, err := listPackages(*token, *server) if err != nil { return err } pkgSlice := make([]string, len(pkgs)) pkgMap := make(map[string]sdk.Package) for idx, pkg := range pkgs { pkgSlice[idx] = pkg.Name pkgMap[pkg.Name] = pkg } pkgQuestion := &survey.Select{ Message: "Select package to update", Options: pkgSlice, } var pkgName string if err := survey.AskOne(pkgQuestion, &pkgName); err != nil { return err } pkg, err := pkgPrompt(pkgMap[pkgName]) if err != nil { return err } client := sdk.New(*token, sdk.WithServer(*server)) if err := client.Update(context.Background(), pkg); err != nil { return err } log.Info().Msgf("Updated %q", pkgName) return nil } }