flag

package
v0.0.0-...-e6aa6c5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package flag implements command line flag utilities for the cff command.

Index

Constants

This section is empty.

Variables

View Source
var ErrHelp = flag.ErrHelp

ErrHelp reports that the user requested help with --help/-h.

Functions

This section is empty.

Types

type Getter

type Getter = flag.Getter

Getter is the interface implemented by custom flag values.

type GetterPtr

type GetterPtr[T any] interface {
	*T
	flag.Getter
}

GetterPtr is satisfied by types that implement flag.Getter on their pointer receiver.

type InOutPair

type InOutPair struct {
	Input, Output string
}

InOutPair is a flag value that holds a pair of values. Two formats are supported:

--flag=INPUT
--flag=INPUT=OUTPUT

For example,

--flag=foo.go=_gen/foo.go --flag=bar.go

func (*InOutPair) Get

func (p *InOutPair) Get() any

Get reports the current value of the flag pair.

func (*InOutPair) Set

func (p *InOutPair) Set(name string) error

Set receives a flag value.

func (*InOutPair) String

func (p *InOutPair) String() string

type List

type List[T any, P GetterPtr[T]] []T

List is a list of values received over the CLI.

Use this for flags that can be accepted multiple times.

func AsList

func AsList[T any, P GetterPtr[T]](vs *[]T) *List[T, P]

AsList builds a flag.List from a pointer to a slice of flag.Getter values.

var list []SomeObject
flagSet.Var(flag.AsList(&list), ...)

func (*List[T, P]) Get

func (vl *List[T, P]) Get() any

Get returns a list of values in this object.

func (*List[T, P]) Set

func (vl *List[T, P]) Set(v string) error

Set receives a single value from the command line.

func (*List[T, P]) String

func (vl *List[T, P]) String() string

type Mode

type Mode uint8

Mode specifies the code generation mode for cff.

const (
	// BaseMode generates cff code without modification.
	BaseMode Mode = iota + 1

	// SourceMapMode generates cff code with line directives to remap
	// generated code locations to source.
	SourceMapMode

	// ModifierMode generates cff code that preserves all original file line
	// locations by generating cff logic into separate modifier
	// functions.
	ModifierMode
)

func (*Mode) Get

func (m *Mode) Get() any

Get reports the current value of the flag.

func (*Mode) Set

func (m *Mode) Set(value string) error

Set receives a flag value from the flag package.

func (Mode) String

func (m Mode) String() string

func (*Mode) UnmarshalText

func (m *Mode) UnmarshalText(text []byte) error

UnmarshalText unmarshals a Mode.

type Set

type Set = flag.FlagSet

Set is a collection of flags.

func NewSet

func NewSet(name string) *Set

NewSet builds a new flag set.

type String

type String string

String is a string received as a command line argument.

We define our own to use it with ListValue.

func (*String) Get

func (s *String) Get() any

Get returns the current string value.

func (*String) Set

func (s *String) Set(v string) error

Set receives a command line value.

func (*String) String

func (s *String) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL