stringlist

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: MIT Imports: 2 Imported by: 4

README

GoDoc

stringlist

Package stringlist implements a custom "stringlist" flag for Go.

Documentation

Overview

Package stringlist implements a custom "stringlist" flag It accepts comma separated values and repeated flag occurrence. Leading and trailing whitespace will be trimmed.

Usage:

var (
	myFlag stringlist.Value
)

func init() {
	flag.Var(&myFlag, "myflag", "a list of strings")
}

Or:

var (
	myFlag = stringlist.Flag("myflag", "a list of strings")
)

func foo() {
	for _, i := range *myFlag {
		// note: you need to dereference the slice
	}
}

Or:

var (
	myFlag []string
)

func init() {
	stringlist.Var(&myFlag, "myflag", "a list of strings")
}

func main() {
	flag.Parse()
	for _, i := range myFlag {
		// note: no need to dereference the slice
	}
}

If you invoke it with:

--myflag a,b --myflag c --myflag "c, d"

myFlag will contain: []string{"a", "b", "c", "d"}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Var added in v1.1.0

func Var(s *[]string, name string, usage string)

Types

type Slice added in v1.1.0

type Slice struct {
	// contains filtered or unexported fields
}

func SliceRef added in v1.1.0

func SliceRef(s *[]string) Slice

func (Slice) Set added in v1.1.0

func (r Slice) Set(args string) error

Set implements the flag.Value interface

func (Slice) String added in v1.1.0

func (r Slice) String() string

type Value

type Value []string

Value implements flag.Value

func Flag

func Flag(name string, usage string) *Value

Flag returns a stringlist flag

func (*Value) Set

func (v *Value) Set(args string) error

Set implements the flag.Value interface

func (*Value) String

func (v *Value) String() string

Jump to

Keyboard shortcuts

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