37 lines
696 B
Go
37 lines
696 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
|
|
"go.jolheiser.com/vanity/sdk"
|
|
|
|
"github.com/AlecAivazis/survey/v2"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func add(token, server *string) func(context.Context, []string) error {
|
|
return func(ctx context.Context, args []string) error {
|
|
pkg, err := pkgPrompt(sdk.Package{})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
client := sdk.New(*token, sdk.WithServer(*server))
|
|
if err := client.Add(context.Background(), pkg); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Info().Msgf("Added %q", pkg.Name)
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func validURL(ans interface{}) error {
|
|
if err := survey.Required(ans); err != nil {
|
|
return err
|
|
}
|
|
_, err := url.Parse(ans.(string))
|
|
return err
|
|
}
|