Add function "AddToCommandFlags" to FlagValidator interface
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 33s
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 33s
Signed-off-by: Jan Tytgat <jan.tytgat@corelayer.eu>
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Oudwins/zog"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
func NewBoolFlag(name string, schema *zog.BoolSchema[bool], usage string) BoolFlag {
|
||||
@ -40,6 +41,10 @@ func (f BoolFlag) Validate() ([]string, error) {
|
||||
return messages, nil
|
||||
}
|
||||
|
||||
func (f BoolFlag) AddToCommandFlags(flagset *pflag.FlagSet, shorthand string, value interface{}) {
|
||||
flagset.BoolVarP(&f.Value, f.Name(), shorthand, value.(bool), f.usage)
|
||||
}
|
||||
|
||||
func NewInt64Flag(name string, schema *zog.NumberSchema[int64], usage string) Int64Flag {
|
||||
return Int64Flag{
|
||||
name: name,
|
||||
@ -74,6 +79,10 @@ func (f Int64Flag) Validate() ([]string, error) {
|
||||
return messages, nil
|
||||
}
|
||||
|
||||
func (f Int64Flag) AddToCommandFlags(flagset *pflag.FlagSet, shorthand string, value interface{}) {
|
||||
flagset.Int64VarP(&f.Value, f.Name(), shorthand, value.(int64), f.usage)
|
||||
}
|
||||
|
||||
func NewStringFlag(name string, schema *zog.StringSchema[string], usage string) StringFlag {
|
||||
return StringFlag{
|
||||
name: name,
|
||||
@ -107,3 +116,7 @@ func (f StringFlag) Validate() ([]string, error) {
|
||||
}
|
||||
return messages, nil
|
||||
}
|
||||
|
||||
func (f StringFlag) AddToCommandFlags(flagset *pflag.FlagSet, shorthand string, value interface{}) {
|
||||
flagset.StringVarP(&f.Value, f.Name(), shorthand, value.(string), f.usage)
|
||||
}
|
||||
|
@ -3,12 +3,15 @@ package flagzog
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
type FlagValidator interface {
|
||||
Name() string
|
||||
Validate() ([]string, error)
|
||||
Usage() string
|
||||
AddToCommandFlags(flagset *pflag.FlagSet, shorthand string, value interface{})
|
||||
}
|
||||
|
||||
func ValidateFlags(ctx context.Context, logger *slog.Logger, flags []FlagValidator) ([]string, error) {
|
||||
|
Reference in New Issue
Block a user