vanity/cmd/vanity-cli/remove.go

49 lines
966 B
Go
Raw Normal View History

package main
import (
"context"
"go.jolheiser.com/vanity/sdk"
"github.com/AlecAivazis/survey/v2"
"github.com/rs/zerolog/log"
)
func remove(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 remove",
Options: pkgSlice,
}
var pkgName string
if err := survey.AskOne(pkgQuestion, &pkgName); err != nil {
return err
}
pkg := sdk.Package{
Name: pkgName,
}
client := sdk.New(*token, sdk.WithServer(*server))
if err := client.Remove(context.Background(), pkg); err != nil {
return err
}
log.Info().Msgf("Removed %q", pkgName)
return nil
}
}