core

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2021 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SelectorTypeNone          = iota // セレクタなし(List系/自前実装系など)
	SelectorTypeRequireSingle        // ID or Name or Tagsを受け取る(複数ヒットNG)
	SelectorTypeRequireMulti         // ID or Name or Tagsを受け取る(複数ヒットOK)
)

Variables

View Source
var (
	ResourceCategoryConfig = Category{
		Key:         "config",
		DisplayName: "Configuration",
		Order:       10,
	}

	ResourceCategoryAuth = Category{
		Key:         "auth",
		DisplayName: "Authentication",
		Order:       20,
	}

	ResourceCategoryComputing = Category{
		Key:         "computing",
		DisplayName: "Computing",
		Order:       30,
	}

	ResourceCategoryStorage = Category{
		Key:         "storage",
		DisplayName: "Storage",
		Order:       40,
	}

	ResourceCategoryNetworking = Category{
		Key:         "networking",
		DisplayName: "Networking",
		Order:       50,
	}

	ResourceCategoryNetworkingSub = Category{
		Key:         "networking-sub",
		DisplayName: "Networking(SubResources)",
		Order:       55,
	}

	ResourceCategoryAppliance = Category{
		Key:         "appliance",
		DisplayName: "Appliance",
		Order:       60,
	}

	ResourceCategorySecureMobile = Category{
		Key:         "securemobile",
		DisplayName: "SecureMobile",
		Order:       70,
	}
	ResourceCategoryCommonServiceItem = Category{
		Key:         "commonserviceitem",
		DisplayName: "Common service items",
		Order:       80,
	}

	ResourceCategoryCommonItem = Category{
		Key:         "commonitem",
		DisplayName: "Common items",
		Order:       90,
	}

	ResourceCategoryBilling = Category{
		Key:         "billing",
		DisplayName: "Billing",
		Order:       100,
	}

	ResourceCategoryLab = Category{
		Key:         "lab",
		DisplayName: "Lab",
		Order:       110,
	}

	ResourceCategoryWebAccel = Category{
		Key:         "webaccel",
		DisplayName: "WebAccelerator",
		Order:       120,
	}

	ResourceCategoryMisc = Category{
		Key:         "misc",
		DisplayName: "Other services",
		Order:       130,
	}

	ResourceCategoryZone = Category{
		Key:         "zone",
		DisplayName: "Region/Zone information",
		Order:       140,
	}

	ResourceCategoryInformation = Category{
		Key:         "information",
		DisplayName: "Service/Product information",
		Order:       150,
	}

	ResourceCategoryOther = Category{
		Key:         "other",
		DisplayName: "Other commands",
		Order:       160,
	}

	ResourceCategories = []Category{
		ResourceCategoryConfig,
		ResourceCategoryAuth,
		ResourceCategoryComputing,
		ResourceCategoryStorage,
		ResourceCategoryNetworking,
		ResourceCategoryNetworkingSub,
		ResourceCategoryAppliance,
		ResourceCategorySecureMobile,
		ResourceCategoryCommonServiceItem,
		ResourceCategoryCommonItem,
		ResourceCategoryBilling,
		ResourceCategoryLab,
		ResourceCategoryWebAccel,
		ResourceCategoryMisc,
		ResourceCategoryZone,
		ResourceCategoryInformation,
		ResourceCategoryOther,
	}
)
View Source
var CommandCategories = []Category{
	{
		Key:         "basic",
		DisplayName: "Basic Commands",
		Order:       100,
	},
	{
		Key:         "connect",
		DisplayName: "Connect Commands",
		Order:       150,
	},
	{
		Key:         "operation",
		DisplayName: "Operation Commands",
		Order:       200,
	},
	{
		Key:         "subnet",
		DisplayName: "Subnet Operation Commands",
		Order:       210,
	},
	{
		Key:         "ipv6",
		DisplayName: "IPv6 Operation Commands",
		Order:       211,
	},
	{
		Key:         "certificate",
		DisplayName: "Certificate Management Commands",
		Order:       220,
	},
	{
		Key:         "cache",
		DisplayName: "Cache Management Commands",
		Order:       221,
	},
	{
		Key:         "power",
		DisplayName: "Power Management Commands",
		Order:       250,
	},
	{
		Key:         "backup",
		DisplayName: "Backup Commands",
		Order:       300,
	},
	{
		Key:         "monitor",
		DisplayName: "Monitoring Commands",
		Order:       500,
	},
	{
		Key:         "other",
		DisplayName: "Other Commands",
		Order:       10000,
	},
}
View Source
var ParameterCategories = []*Category{
	{
		Key:         "common",
		DisplayName: "Common options",
		Order:       50,
	},
	{
		Key:         "plan",
		DisplayName: "Plan options",
		Order:       60,
	},
	{
		Key:         "diskedit",
		DisplayName: "Edit disk options",
		Order:       200,
	},
	{
		Key:         "network",
		DisplayName: "Network options",
		Order:       200,
	},
	{
		Key:         "health",
		DisplayName: "Health check options",
		Order:       200,
	},
	{
		Key:         "filter",
		DisplayName: "Filter options",
		Order:       math.MaxInt32 - 100,
	},
	{
		Key:         "limit-offset",
		DisplayName: "Limit/Offset options",
		Order:       math.MaxInt32 - 90,
	},
	{
		Key:         "sort",
		DisplayName: "Sort options",
		Order:       math.MaxInt32 - 80,
	},
	{
		Key:         "monitor",
		DisplayName: "Monitor options",
		Order:       math.MaxInt32 - 70,
	},
	{
		Key:         "delete",
		DisplayName: "Delete options",
		Order:       math.MaxInt32 - 60,
	},
	{
		Key:         "zone",
		DisplayName: "Zone options",
		Order:       math.MaxInt32 - 50,
	},
	{
		Key:         "error",
		DisplayName: "Error handling options",
		Order:       math.MaxInt32 - 40,
	},
	{
		Key:         "wait",
		DisplayName: "Wait options",
		Order:       math.MaxInt32 - 30,
	},
	{
		Key:         "input",
		DisplayName: "Input options",
		Order:       math.MaxInt32 - 20,
	},
	{
		Key:         "output",
		DisplayName: "Output options",
		Order:       math.MaxInt32 - 10,
	},
	{
		Key:         "example",
		DisplayName: "Parameter example",
		Order:       math.MaxInt32 - 5,
	},
	{
		Key:         "default",
		DisplayName: "Other options",
		Order:       math.MaxInt32,
	},
}

Functions

func BuildFlagsUsage

func BuildFlagsUsage(cmd *cobra.Command, sets []*FlagSet)

func BuildRootCommandsUsage

func BuildRootCommandsUsage(cmd *cobra.Command, commands []*CategorizedResources)

Types

type CategorizedCommands

type CategorizedCommands struct {
	Category Category
	Commands []*Command
}

type CategorizedResources

type CategorizedResources struct {
	Category  Category
	Resources []*Resource
}

type Category

type Category struct {
	Key         string
	DisplayName string
	Order       int
}

func (*Category) Equals

func (c *Category) Equals(target *Category) bool

type Command

type Command struct {
	Name      string   // コマンド名、ケバブケース(ハイフン区切り)で指定すること
	Aliases   []string // エイリアス
	Usage     string
	ArgsUsage string // Argumentsの説明、省略した場合はSelectorTypeの値に応じた内容が設定される

	Category string // カテゴリーのキー
	Order    int    // コマンドが属するリソース内での並び順

	// コマンド動作関連
	SelectorType   SelectorType
	NoProgress     bool // コマンド実行時のプログレス表示の有無
	ConfirmMessage string

	// パラメータ関連
	ParameterCategories  []Category
	ParameterInitializer func() interface{}
	ServiceFuncAltName   string // デフォルトのlibsacloud service呼び出しコード生成用、空の場合はNameをCamelizeしたものが利用される // TODO libsacloud側で対応すべき

	// テーブル形式での出力対象列。省略した場合はIDとNameが出力される
	ColumnDefs []output.ColumnDef

	// TODO そのうちDeprecatedWarningとかも対応する
	ExperimentWarning string

	// 操作対象リソースの一覧取得用。通常はResourceに紐づけられたfuncを利用する
	ListAllFunc func(ctx cli.Context, parameter interface{}) ([]interface{}, error)

	// 特殊な引数補完をしたい場合に設定する
	CustomCompletionFunc func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)

	// カスタムバリデーション用。空の場合usacloud/pkg/validate.Execが実行される
	ValidateFunc ValidateFunc

	// コマンドの実処理。設定してない場合はデフォルトのlibsacloud service呼び出しが行われる
	Func func(ctx cli.Context, parameter interface{}) ([]interface{}, error)
	// contains filtered or unexported fields
}

Command コマンド定義、実行時のコンテキスト(設定保持)にもなる

func (*Command) CLICommand

func (c *Command) CLICommand() *cobra.Command

func (*Command) CompleteArgs

func (c *Command) CompleteArgs(ctx cli.Context, cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)

func (*Command) ParameterCategoryBy

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

func (*Command) Run

func (c *Command) Run(ctx cli.Context, cmd *cobra.Command, args []string) error

func (*Command) ValidateSchema

func (c *Command) ValidateSchema() error

type ExampleHolder

type ExampleHolder interface {
	ExampleParameters(ctx cli.Context) interface{}
}

type FlagInitializer

type FlagInitializer interface {
	SetupCobraCommandFlags(cmd *cobra.Command)
}

type FlagSet

type FlagSet struct {
	Title string
	Flags *pflag.FlagSet
}

type FlagValueCleaner

type FlagValueCleaner interface {
	CleanupEmptyValue(flags *pflag.FlagSet)
}

type IDFlag

type IDFlag types.ID

func NewIDFlag

func NewIDFlag(val *types.ID, p *types.ID) *IDFlag

func (*IDFlag) Set

func (v *IDFlag) Set(id string) error

func (*IDFlag) String

func (v *IDFlag) String() string

func (*IDFlag) Type

func (v *IDFlag) Type() string

type IDSliceFlag

type IDSliceFlag []types.ID

func NewIDSliceFlag

func NewIDSliceFlag(val *[]types.ID, p *[]types.ID) *IDSliceFlag

func (*IDSliceFlag) Set

func (v *IDSliceFlag) Set(ids string) error

func (*IDSliceFlag) String

func (v *IDSliceFlag) String() string

func (*IDSliceFlag) Type

func (v *IDSliceFlag) Type() string

type ParameterCustomizer

type ParameterCustomizer interface {
	Customize(ctx cli.Context) error
}

type Progress

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

func NewProgress

func NewProgress(ctx cli.Context) *Progress

func (*Progress) Close

func (p *Progress) Close()

func (*Progress) Exec

func (p *Progress) Exec(f func() error) error

func (*Progress) Start

func (p *Progress) Start()

type Resource

type Resource struct {
	Name               string
	Aliases            []string
	Usage              string
	DefaultCommandName string
	Category           Category
	Warning            string
	IsGlobalResource   bool
	ServiceType        reflect.Type // リソースに対応するlibsacloud serviceの型情報、コード生成用
	SkipLoadingProfile bool
	// contains filtered or unexported fields
}

func (*Resource) AddCommand

func (r *Resource) AddCommand(command *Command)

func (*Resource) CLICommand

func (r *Resource) CLICommand() *cobra.Command

func (*Resource) CategorizedCommands

func (r *Resource) CategorizedCommands() []*CategorizedCommands

func (*Resource) Commands

func (r *Resource) Commands() []*Command

type Resources

type Resources []*Resource

func (Resources) CategorizedResources

func (r Resources) CategorizedResources() []*CategorizedResources

type SelectorType

type SelectorType int

type ValidateFunc

type ValidateFunc func(ctx cli.Context, parameter interface{}) error

Jump to

Keyboard shortcuts

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