ask

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2020 License: MIT Imports: 10 Imported by: 3

README

ask

A golang library to ask user for typed answers, passwords and stuff

Go Report Card Coverage Status

Install

go get github.com/kyoh86/ask

LICENSE

MIT License

This is distributed under the MIT License.

Documentation

Overview

Package ask A golang library to ask user for typed answers, passwords and stuff

Index

Constants

View Source
const (
	// VarTypeString indicates the string
	VarTypeString = VarType("string")

	// VarTypeBool indicates the bool
	VarTypeBool = VarType("bool")

	// VarTypeYesNo indicates the bool
	VarTypeYesNo = VarType("yesNo")

	// VarTypeUint indicates the uint
	VarTypeUint = VarType("uint")

	// VarTypeUint8 indicates the uint8
	VarTypeUint8 = VarType("uint8")

	// VarTypeUint16 indicates the uint16
	VarTypeUint16 = VarType("uint16")

	// VarTypeUint32 indicates the uint32
	VarTypeUint32 = VarType("uint32")

	// VarTypeUint64 indicates the uint64
	VarTypeUint64 = VarType("uint64")

	// VarTypeInt indicates the int
	VarTypeInt = VarType("int")

	// VarTypeInt8 indicates the int8
	VarTypeInt8 = VarType("int8")

	// VarTypeInt16 indicates the int16
	VarTypeInt16 = VarType("int16")

	// VarTypeInt32 indicates the int32
	VarTypeInt32 = VarType("int32")

	// VarTypeInt64 indicates the int64
	VarTypeInt64 = VarType("int64")

	// VarTypeFloat32 indicates the float32
	VarTypeFloat32 = VarType("float32")

	// VarTypeFloat64 indicates the float64
	VarTypeFloat64 = VarType("float64")
)

Variables

View Source
var ErrSkip = errors.New("skip")

ErrSkip will skip to ask a value.

Functions

func Bool

func Bool() (*bool, error)

Bool takes bool value from user input

func Float32

func Float32() (*float32, error)

Float32 takes float32 value from user input

func Float64

func Float64() (*float64, error)

Float64 takes float64 value from user input

func Int

func Int() (*int, error)

Int takes int value from user input

func Int16

func Int16() (*int16, error)

Int16 takes int16 value from user input

func Int32

func Int32() (*int32, error)

Int32 takes int32 value from user input

func Int64

func Int64() (*int64, error)

Int64 takes int64 value from user input

func Int8

func Int8() (*int8, error)

Int8 takes int8 value from user input

func Interface

func Interface(t VarType) (interface{}, error)

Interface will get a value that type of 't'.

func String

func String() (*string, error)

String takes string value from user input

func Uint

func Uint() (*uint, error)

Uint takes uint value from user input

func Uint16

func Uint16() (*uint16, error)

Uint16 takes uint16 value from user input

func Uint32

func Uint32() (*uint32, error)

Uint32 takes uint32 value from user input

func Uint64

func Uint64() (*uint64, error)

Uint64 takes uint64 value from user input

func Uint8

func Uint8() (*uint8, error)

Uint8 takes uint8 value from user input

func YesNo

func YesNo() (*bool, error)

YesNo takes bool value from user input

Types

type Collector

type Collector []Doer

Collector will collect values to ask.

func (Collector) Do

func (c Collector) Do() error

Do will get all values from input.

func (*Collector) Push

func (c *Collector) Push(d Doer)

Push new value to ask.

type Doer

type Doer interface {
	Do() error
}

Doer will do.

func BoolVar

func BoolVar(v *bool) Doer

BoolVar sets a bool variable, "v" to accept user input

func Float32Var

func Float32Var(v *float32) Doer

Float32Var sets a float32 variable, "v" to accept user input

func Float64Var

func Float64Var(v *float64) Doer

Float64Var sets a float64 variable, "v" to accept user input

func Int16Var

func Int16Var(v *int16) Doer

Int16Var sets a int16 variable, "v" to accept user input

func Int32Var

func Int32Var(v *int32) Doer

Int32Var sets a int32 variable, "v" to accept user input

func Int64Var

func Int64Var(v *int64) Doer

Int64Var sets a int64 variable, "v" to accept user input

func Int8Var

func Int8Var(v *int8) Doer

Int8Var sets a int8 variable, "v" to accept user input

func IntVar

func IntVar(v *int) Doer

IntVar sets a int variable, "v" to accept user input

func StringVar

func StringVar(v *string) Doer

StringVar sets a string variable, "v" to accept user input

func Uint16Var

func Uint16Var(v *uint16) Doer

Uint16Var sets a uint16 variable, "v" to accept user input

func Uint32Var

func Uint32Var(v *uint32) Doer

Uint32Var sets a uint32 variable, "v" to accept user input

func Uint64Var

func Uint64Var(v *uint64) Doer

Uint64Var sets a uint64 variable, "v" to accept user input

func Uint8Var

func Uint8Var(v *uint8) Doer

Uint8Var sets a uint8 variable, "v" to accept user input

func UintVar

func UintVar(v *uint) Doer

UintVar sets a uint variable, "v" to accept user input

func YesNoVar

func YesNoVar(v *bool) Doer

YesNoVar sets a bool variable, "v" to accept user input

type ParseFunc added in v0.0.5

type ParseFunc func(string) error

func (ParseFunc) UnmarshalText added in v0.0.5

func (f ParseFunc) UnmarshalText(raw []byte) error

type Prototype

type Prototype struct {
	Hidden     bool
	Default    string
	Envar      string
	Validation func(string) error
	Matcher    *regexp.Regexp
	Enum       []string
	Column     int
	Optional   bool
	Limit      int
	Reader     io.Reader
	Writer     io.Writer
	Message    string
	Before     func() error
	BeforeEach func(int) error
}

Prototype gives handler some options

type Service

type Service struct {
	Prototype
}

Service is the handler to ask values.

func Before

func Before(v func() error) *Service

Before makes new Service with new Before option

func BeforeEach

func BeforeEach(v func(int) error) *Service

BeforeEach makes new Service with new BeforeEach option

func Column

func Column(v int) *Service

Column makes new Service with new Column option

func Default

func Default(v string) *Service

Default makes new Service with new Default option

func Enum

func Enum(v []string) *Service

Enum makes new Service with new Enum option

func Envar

func Envar(v string) *Service

Envar makes new Service with new Envar option

func Hidden

func Hidden(v bool) *Service

Hidden makes new Service with new Hidden option

func Limit

func Limit(v int) *Service

Limit makes new Service with new Limit option

func Matcher

func Matcher(v *regexp.Regexp) *Service

Matcher makes new Service with new Matcher option

func Message

func Message(v string) *Service

Message makes new Service with new Message option

func Optional

func Optional(v bool) *Service

Optional makes new Service with new Optional option

func Reader

func Reader(v io.Reader) *Service

Reader makes new Service with new Reader option

func Validation

func Validation(v func(string) error) *Service

Validation makes new Service with new Validation option

func Writer

func Writer(v io.Writer) *Service

Writer makes new Service with new Writer option

func (*Service) Ask

func (s *Service) Ask(unmarshaler encoding.TextUnmarshaler) error

Ask will get a value from input and pass it to encoding.TextUnmarshaler.

func (*Service) AskParseFunc added in v0.0.5

func (s *Service) AskParseFunc(parse ParseFunc) error

AskParseFunc will get a value from input and pass it to parser func.

func (*Service) AskUnmarshalFunc added in v0.0.5

func (s *Service) AskUnmarshalFunc(unmarshal UnmarshalFunc) error

AskFunc will get a value from input and pass it to unmarshal func.

func (Service) Before

func (s Service) Before(v func() error) *Service

Before makes new Service with new Before option

func (Service) BeforeEach

func (s Service) BeforeEach(v func(int) error) *Service

BeforeEach makes new Service with new BeforeEach option

func (Service) Bool

func (s Service) Bool() (*bool, error)

Bool takes bool value from user input

func (Service) BoolVar

func (s Service) BoolVar(v *bool) Doer

BoolVar sets a bool variable, "v" to accept user input

func (Service) Column

func (s Service) Column(v int) *Service

Column makes new Service with new Column option

func (Service) Default

func (s Service) Default(v string) *Service

Default makes new Service with new Default option

func (Service) Enum

func (s Service) Enum(v []string) *Service

Enum makes new Service with new Enum option

func (Service) Envar

func (s Service) Envar(v string) *Service

Envar makes new Service with new Envar option

func (Service) Float32

func (s Service) Float32() (*float32, error)

Float32 takes float32 value from user input

func (Service) Float32Var

func (s Service) Float32Var(v *float32) Doer

Float32Var sets a float32 variable, "v" to accept user input

func (Service) Float64

func (s Service) Float64() (*float64, error)

Float64 takes float64 value from user input

func (Service) Float64Var

func (s Service) Float64Var(v *float64) Doer

Float64Var sets a float64 variable, "v" to accept user input

func (Service) Hidden

func (s Service) Hidden(v bool) *Service

Hidden makes new Service with new Hidden option

func (Service) Int

func (s Service) Int() (*int, error)

Int takes int value from user input

func (Service) Int16

func (s Service) Int16() (*int16, error)

Int16 takes int16 value from user input

func (Service) Int16Var

func (s Service) Int16Var(v *int16) Doer

Int16Var sets a int16 variable, "v" to accept user input

func (Service) Int32

func (s Service) Int32() (*int32, error)

Int32 takes int32 value from user input

func (Service) Int32Var

func (s Service) Int32Var(v *int32) Doer

Int32Var sets a int32 variable, "v" to accept user input

func (Service) Int64

func (s Service) Int64() (*int64, error)

Int64 takes int64 value from user input

func (Service) Int64Var

func (s Service) Int64Var(v *int64) Doer

Int64Var sets a int64 variable, "v" to accept user input

func (Service) Int8

func (s Service) Int8() (*int8, error)

Int8 takes int8 value from user input

func (Service) Int8Var

func (s Service) Int8Var(v *int8) Doer

Int8Var sets a int8 variable, "v" to accept user input

func (Service) IntVar

func (s Service) IntVar(v *int) Doer

IntVar sets a int variable, "v" to accept user input

func (Service) Interface

func (s Service) Interface(t VarType) (interface{}, error)

Interface will get a value that type of 't'.

func (Service) Limit

func (s Service) Limit(v int) *Service

Limit makes new Service with new Limit option

func (Service) Matcher

func (s Service) Matcher(v *regexp.Regexp) *Service

Matcher makes new Service with new Matcher option

func (Service) Message

func (s Service) Message(v string) *Service

Message makes new Service with new Message option

func (Service) Optional

func (s Service) Optional(v bool) *Service

Optional makes new Service with new Optional option

func (Service) Reader

func (s Service) Reader(v io.Reader) *Service

Reader makes new Service with new Reader option

func (Service) String

func (s Service) String() (*string, error)

String takes string value from user input

func (Service) StringVar

func (s Service) StringVar(v *string) Doer

StringVar sets a string variable, "v" to accept user input

func (Service) Uint

func (s Service) Uint() (*uint, error)

Uint takes uint value from user input

func (Service) Uint16

func (s Service) Uint16() (*uint16, error)

Uint16 takes uint16 value from user input

func (Service) Uint16Var

func (s Service) Uint16Var(v *uint16) Doer

Uint16Var sets a uint16 variable, "v" to accept user input

func (Service) Uint32

func (s Service) Uint32() (*uint32, error)

Uint32 takes uint32 value from user input

func (Service) Uint32Var

func (s Service) Uint32Var(v *uint32) Doer

Uint32Var sets a uint32 variable, "v" to accept user input

func (Service) Uint64

func (s Service) Uint64() (*uint64, error)

Uint64 takes uint64 value from user input

func (Service) Uint64Var

func (s Service) Uint64Var(v *uint64) Doer

Uint64Var sets a uint64 variable, "v" to accept user input

func (Service) Uint8

func (s Service) Uint8() (*uint8, error)

Uint8 takes uint8 value from user input

func (Service) Uint8Var

func (s Service) Uint8Var(v *uint8) Doer

Uint8Var sets a uint8 variable, "v" to accept user input

func (Service) UintVar

func (s Service) UintVar(v *uint) Doer

UintVar sets a uint variable, "v" to accept user input

func (Service) Validation

func (s Service) Validation(v func(string) error) *Service

Validation makes new Service with new Validation option

func (*Service) Var

func (s *Service) Var(parse encoding.TextUnmarshaler) Doer

Var sets encoding.TextUnmarshaler.

func (Service) Writer

func (s Service) Writer(v io.Writer) *Service

Writer makes new Service with new Writer option

func (Service) YesNo

func (s Service) YesNo() (*bool, error)

YesNo takes bool value from user input

func (Service) YesNoVar

func (s Service) YesNoVar(v *bool) Doer

YesNoVar sets a bool variable, "v" to accept user input

type UnmarshalFunc added in v0.0.5

type UnmarshalFunc func([]byte) error

func (UnmarshalFunc) UnmarshalText added in v0.0.5

func (f UnmarshalFunc) UnmarshalText(raw []byte) error

type VarType

type VarType string

VarType indicates a type of a variable.

func VarTypes

func VarTypes() []VarType

VarTypes is the all types.

func (VarType) String

func (t VarType) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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