package main

import "fmt"

// FormatFlag is a custom pflag.Value for handling --format validation and completion
type FormatFlag string

const (
	// FormatPNG represents PNG output format for identicon generation
	FormatPNG FormatFlag = "png"

	// FormatSVG represents SVG output format for identicon generation
	FormatSVG FormatFlag = "svg"
)

// String is used both by pflag and fmt.Stringer
func (f *FormatFlag) String() string {
	return string(*f)
}

// Set must have pointer receiver, so it can change the value of f.
func (f *FormatFlag) Set(v string) error {
	switch v {
	case "png", "svg":
		*f = FormatFlag(v)
		return nil
	default:
		return fmt.Errorf(`must be one of "png" or "svg"`)
	}
}

// Type is only used in help text
func (f *FormatFlag) Type() string {
	return "string"
}
