schema

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CommonParamCategory = &Category{
	Key:         "common",
	DisplayName: "Common options",
	Order:       math.MaxInt32 - 30,
}
View Source
var DefaultCommandCategory = &Category{
	Key:         "default",
	DisplayName: "",
	Order:       math.MaxInt32,
}
View Source
var DefaultParamCategory = &Category{
	Key:         "default",
	DisplayName: "Other options",
	Order:       math.MaxInt32,
}
View Source
var DefaultResourceCategory = &Category{
	Key:         "default",
	DisplayName: "",
	Order:       math.MaxInt32,
}
View Source
var FilterParamCategory = &Category{
	Key:         "filter",
	DisplayName: "Filter options",
	Order:       math.MaxInt32 - 60,
}
View Source
var InputParamCategory = &Category{
	Key:         "Input",
	DisplayName: "Input options",
	Order:       math.MaxInt32 - 20,
}
View Source
var LimitOffsetParamCategory = &Category{
	Key:         "limit-offset",
	DisplayName: "Limit/Offset options",
	Order:       math.MaxInt32 - 50,
}
View Source
var OutputParamCategory = &Category{
	Key:         "output",
	DisplayName: "Output options",
	Order:       math.MaxInt32 - 10,
}
View Source
var SortParamCategory = &Category{
	Key:         "sort",
	DisplayName: "Sort options",
	Order:       math.MaxInt32 - 40,
}

Functions

This section is empty.

Types

type Category

type Category struct {
	Key         string
	DisplayName string
	Order       int
}

type Command

type Command struct {
	Type      CommandType
	Aliases   []string
	Usage     string
	ArgsUsage string

	Category string
	Order    int

	Params                   map[string]*Schema
	ParamCategories          []Category
	AltResource              string // 空の場合はResourceのキーをCamelizeしてsacloud.XXXを対象とする。
	ListResultFieldName      string
	SkipAuth                 bool
	SkipAfterSecondArgs      bool // trueの場合、2番目以降の引数(1番目はID or 名称)の解析を行わない
	UseCustomCommand         bool
	UseCustomArgCompletion   bool
	UseCustomFlagsCompletion bool
	NeedlessConfirm          bool
	ConfirmMessage           string
	ExperimentWarning        string

	NoOutput bool

	NoSelector bool // --selectorオプション利用有無、trueの場合利用しない

	TableType          output.TableType
	IncludeFields      []string           // for output.TableDetail
	ExcludeFields      []string           // for output.TableDetail
	TableColumnDefines []output.ColumnDef // for output.TableSimple
}

func (*Command) BuildedParams added in v0.0.2

func (c *Command) BuildedParams() SortableParams

func (*Command) ParamCategory

func (c *Command) ParamCategory(key string) *Category

func (*Command) Validate

func (c *Command) Validate() []error

type CommandType

type CommandType int //go:generate stringer -type=CommandType :: manual

CommandType is an enum of the type that can be represented by a schema.

const (
	CommandInvalid CommandType = iota
	CommandList
	CommandCreate
	CommandRead
	CommandUpdate
	CommandDelete
	CommandManipulateMulti
	CommandManipulateSingle
	CommandManipulateIDOnly
	CommandCustom
)

func (CommandType) CanUseSelector added in v0.0.13

func (c CommandType) CanUseSelector() bool

CanUseSelector タグなどでのセレクターが利用可能なコマンドタイプであるか

func (CommandType) IsNeedConfirmType added in v0.0.2

func (c CommandType) IsNeedConfirmType() bool

IsNeedConfirmType コマンド実行時に確認ダイアログが必要なコマンドタイプであるか

func (CommandType) IsNeedIDOnlyType added in v0.0.2

func (c CommandType) IsNeedIDOnlyType() bool

IsNeedIDOnlyType 引数にIDのみ受け付けるコマンドタイプであるか

func (CommandType) IsNeedSingleIDType added in v0.0.2

func (c CommandType) IsNeedSingleIDType() bool

IsNeedSingleIDType 引数に単一の対象リソースを要求するコマンドタイプであるか

func (CommandType) IsRequiredIDType

func (c CommandType) IsRequiredIDType() bool

IsRequiredIDType 引数に対象リソースの指定を要求するコマンドタイプであるか

func (CommandType) String

func (i CommandType) String() string

type CompletionContext

type CompletionContext interface {
	GetAPIClient() *api.Client
	Args() []string
}

type CompletionFunc added in v0.0.9

type CompletionFunc func(ctx CompletionContext, currentValue string) []string

func CompleteInIntValues added in v0.0.2

func CompleteInIntValues(values ...int) CompletionFunc

func CompleteInStrValues added in v0.0.2

func CompleteInStrValues(values ...string) CompletionFunc

type HandlerType

type HandlerType int //go:generate stringer -type=HandlerType :: manual

HandlerType is an enum of the type that can be represented by a schema.

const (
	HandlerPathThrough HandlerType = iota
	HandlerPathThroughEach
	HandlerSort
	HandlerFilterBy
	HandlerAndParams
	HandlerOrParams
	HandlerCustomFunc
	HandlerFilterFunc
	HandlerNoop
)

func (HandlerType) CanSetDestinationProp

func (h HandlerType) CanSetDestinationProp() bool

CanSetDestinationProp return true when HandlerType is able to have DestinationProp

func (HandlerType) IsNeedSliceValue

func (h HandlerType) IsNeedSliceValue() bool

IsNeedSliceValue return true when HandlerType is need Slice ValueType

func (HandlerType) IsWhenListOnly

func (h HandlerType) IsWhenListOnly() bool

IsWhenListOnly return true when HandlerType is able to use with CommandList

func (HandlerType) String

func (i HandlerType) String() string

type ListFilterFunc added in v0.0.10

type ListFilterFunc func(list []interface{}, item interface{}, param interface{}) bool

type Resource

type Resource struct {
	Aliases             []string
	Usage               string
	Commands            map[string]*Command
	DefaultCommand      string // 空の場合は`resource -h`
	AltResource         string // 空の場合はResourceのキーをCamelizeしてsacloud.XXXを対象とする。
	ListResultFieldName string
	CommandCategories   []Category
	ResourceCategory    Category
	SkipApplyConfigFile bool
	ExperimentWarning   string
}

func (*Resource) CommandCategory

func (r *Resource) CommandCategory(key string) *Category

func (*Resource) SortedCommands

func (r *Resource) SortedCommands() SortableCommands

type Schema

type Schema struct {
	Type ValueType

	DefaultValue interface{}
	DefaultText  string
	EnvVars      []string
	InputDefault interface{}
	Aliases      []string
	Description  string // Usage -> cli
	Hidden       bool

	Category string
	Order    int

	Required      bool
	SakuraID      bool
	ConflictsWith []string
	ValidateFunc  ValidateFunc

	MaxItems int
	MinItems int

	HandlerType     HandlerType
	DestinationProp string
	CustomHandler   ValueHandlerFunc
	FilterFunc      ListFilterFunc

	CompleteFunc CompletionFunc
}

func (*Schema) Validate

func (s *Schema) Validate(name string) []error

type SortableCommand

type SortableCommand struct {
	Category   *Category
	Command    *Command
	CommandKey string
}

type SortableCommands

type SortableCommands []SortableCommand

func (SortableCommands) Len

func (s SortableCommands) Len() int

func (SortableCommands) Less

func (s SortableCommands) Less(i, j int) bool

func (SortableCommands) Swap

func (s SortableCommands) Swap(i, j int)

type SortableParam

type SortableParam struct {
	Category *Category
	Param    *Schema
	ParamKey string
}

type SortableParams

type SortableParams []SortableParam

func (SortableParams) Get added in v0.0.13

func (s SortableParams) Get(key string) *SortableParam

func (SortableParams) Len

func (s SortableParams) Len() int

func (SortableParams) Less

func (s SortableParams) Less(i, j int) bool

func (SortableParams) Swap

func (s SortableParams) Swap(i, j int)

type ValidateFunc added in v0.0.9

type ValidateFunc func(string, interface{}) []error

func ValidateDateTimeString added in v0.0.2

func ValidateDateTimeString() ValidateFunc

func ValidateFileExists added in v0.0.2

func ValidateFileExists() ValidateFunc

func ValidateIPv4Address added in v0.0.2

func ValidateIPv4Address() ValidateFunc

func ValidateIPv4AddressWithPrefix added in v0.0.9

func ValidateIPv4AddressWithPrefix() ValidateFunc

func ValidateIPv4AddressWithPrefixOption added in v0.0.9

func ValidateIPv4AddressWithPrefixOption() ValidateFunc

func ValidateIPv6Address added in v0.3.0

func ValidateIPv6Address() ValidateFunc

func ValidateInIntValues added in v0.0.2

func ValidateInIntValues(allows ...int) ValidateFunc

func ValidateInStrValues added in v0.0.2

func ValidateInStrValues(allows ...string) ValidateFunc

func ValidateIntRange added in v0.0.2

func ValidateIntRange(min int, max int) ValidateFunc

func ValidateIntSlice added in v0.0.2

func ValidateIntSlice(validator ValidateFunc) ValidateFunc

func ValidateMACAddress added in v0.0.9

func ValidateMACAddress() ValidateFunc

func ValidateMemberCD added in v0.0.2

func ValidateMemberCD() ValidateFunc

func ValidateMulti added in v0.0.2

func ValidateMulti(validators ...ValidateFunc) ValidateFunc

func ValidateMultiOr added in v0.7.0

func ValidateMultiOr(validators ...ValidateFunc) ValidateFunc

func ValidateSakuraID added in v0.0.2

func ValidateSakuraID() ValidateFunc

func ValidateSakuraShortID added in v0.0.2

func ValidateSakuraShortID(digit int) ValidateFunc

func ValidateSlackWebhookURL added in v0.15.0

func ValidateSlackWebhookURL() ValidateFunc

func ValidateStdinExists added in v0.7.0

func ValidateStdinExists() ValidateFunc

func ValidateStrLen added in v0.0.2

func ValidateStrLen(min int, max int) ValidateFunc

func ValidateStringSlice added in v0.0.2

func ValidateStringSlice(validator ValidateFunc) ValidateFunc

type ValueHandlerFunc added in v0.0.9

type ValueHandlerFunc func(name string, src interface{}, dest interface{})

type ValueType

type ValueType int //go:generate stringer -type=ValueType :: manual

ValueType is an enum of the type that can be represented by a schema.

const (
	TypeInvalid ValueType = iota
	TypeBool
	TypeInt
	TypeInt64
	TypeFloat
	TypeString
	TypeIntList
	TypeStringList
	TypeId
	TypeIdList
)

func (ValueType) IsSliceType

func (v ValueType) IsSliceType() bool

IsSliceType return true if type is TypeIntList or TypeStringList

func (ValueType) String

func (i ValueType) String() string

Jump to

Keyboard shortcuts

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