unexpose errors when possible, add documentation where not

Signed-off-by: Moshe Beladev <moshebe123@gmail.com>
This commit is contained in:
Moshe Beladev 2021-01-31 10:42:52 +02:00
Родитель 760afc1304
Коммит 645ce6c610
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 75E75C0711A042E5
3 изменённых файлов: 7 добавлений и 6 удалений

Просмотреть файл

@ -41,7 +41,7 @@ type rmOptions struct {
force bool
}
var ErrCanceled = errors.New("canceled")
var errCanceled = errors.New("canceled")
func newRmCmd(streams command.Streams, hubClient *hub.Client, parent string) *cobra.Command {
var opts rmOptions
@ -55,7 +55,7 @@ func newRmCmd(streams command.Streams, hubClient *hub.Client, parent string) *co
},
RunE: func(cmd *cobra.Command, args []string) error {
err := runRm(cmd.Context(), streams, hubClient, opts, args[0])
if err == nil || err == ErrCanceled {
if err == nil || err == errCanceled {
return nil
}
return err
@ -92,7 +92,7 @@ func runRm(ctx context.Context, streams command.Streams, hubClient *hub.Client,
input := ""
select {
case <-ctx.Done():
return ErrCanceled
return errCanceled
case input = <-userIn:
}
if input != namedRef.Name() {

Просмотреть файл

@ -41,7 +41,7 @@ type rmOptions struct {
force bool
}
var ErrCanceled = errors.New("canceled")
var errCanceled = errors.New("canceled")
func newRmCmd(streams command.Streams, hubClient *hub.Client, parent string) *cobra.Command {
var opts rmOptions
@ -55,7 +55,7 @@ func newRmCmd(streams command.Streams, hubClient *hub.Client, parent string) *co
},
RunE: func(cmd *cobra.Command, args []string) error {
err := runRm(cmd.Context(), streams, hubClient, opts, args[0])
if err == nil || err == ErrCanceled {
if err == nil || err == errCanceled {
return nil
}
return err
@ -89,7 +89,7 @@ func runRm(ctx context.Context, streams command.Streams, hubClient *hub.Client,
input := ""
select {
case <-ctx.Done():
return ErrCanceled
return errCanceled
case input = <-userIn:
}
if strings.ToLower(input) != "y" {

Просмотреть файл

@ -35,6 +35,7 @@ import (
"github.com/docker/hub-tool/internal/hub"
)
// ErrCanceled represents a normally canceled operation
var ErrCanceled = errors.New("canceled")
// RunLogin logs the user and asks for the 2FA code if needed