cobrautils

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: MIT Imports: 6 Imported by: 6

README

Cobra Utils

  • reflectを用いてcobra.Commandのプライベートなフィールドにアクセスします。
  • コマンドのテスト可用性と可読性を両立するサブコマンド構成を実現するための関数を提供します。
  • PersistentPreRunEを再帰的に実行するユーティリティを提供します。

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HelpTemplate string

Functions

func AddSubCmds added in v0.0.3

func AddSubCmds(cmds ...*cobra.Command)

func AdditionalCommands added in v0.0.3

func AdditionalCommands(additionalCommands string) labelOptArg

func AddtionalHelpTopics added in v0.0.3

func AddtionalHelpTopics(addtionalHelpTopics string) labelOptArg

func Aliases added in v0.0.3

func Aliases(aliases string) labelOptArg

func AvailableCommands added in v0.0.3

func AvailableCommands(availableCommands string) labelOptArg

func BindSubCmds

func BindSubCmds(root *cobra.Command)

func CallCmd

func CallCmd(me *cobra.Command, target cobra.Command, args ...string) error

指定されたサブコマンドを、現在のcmdと同じ環境で実行します

func Examples added in v0.0.3

func Examples(examples string) labelOptArg

func Flags added in v0.0.3

func Flags(flags string) labelOptArg

func GenerateTemplate added in v0.0.3

func GenerateTemplate(label *HelpLabels) string

func GetHelpCommand

func GetHelpCommand(cmd *cobra.Command) *cobra.Command

func GetInternalAllSubCmds

func GetInternalAllSubCmds(cmd *cobra.Command) []*cobra.Command

func GetInternalSubCmdByName

func GetInternalSubCmdByName(cmd *cobra.Command, name string) *cobra.Command

func GetSubCmds

func GetSubCmds() []*cobra.Command

func GlobalFlags added in v0.0.3

func GlobalFlags(globalFlags string) labelOptArg

func Usage added in v0.0.3

func Usage(usage string) labelOptArg

func UseCustomizableHelpTemplate added in v0.0.3

func UseCustomizableHelpTemplate(cmd *cobra.Command, label *HelpLabels)

func UseHelp added in v0.0.3

func UseHelp(useHelp string) labelOptArg

func WithParentPersistentPostRun added in v0.0.3

func WithParentPersistentPostRun(f func(cmd *cobra.Command, args []string)) func(cmd *cobra.Command, args []string)

func WithParentPersistentPostRunE added in v0.0.3

func WithParentPersistentPostRunE(f func(cmd *cobra.Command, args []string) error) func(cmd *cobra.Command, args []string) error

func WithParentPersistentPreRun added in v0.0.3

func WithParentPersistentPreRun(f func(cmd *cobra.Command, args []string)) func(cmd *cobra.Command, args []string)

func WithParentPersistentPreRunE

func WithParentPersistentPreRunE(f func(cmd *cobra.Command, args []string) error) func(cmd *cobra.Command, args []string) error

Types

type HelpLabels added in v0.0.3

type HelpLabels struct {
	Usage               string
	Aliases             string
	Examples            string
	AvailableCommands   string
	AdditionalCommands  string
	Flags               string
	GlobalFlags         string
	AddtionalHelpTopics string
	UseHelp             string
}

func DefaultHelpLabels added in v0.0.3

func DefaultHelpLabels() *HelpLabels

func NewLabel added in v0.0.3

func NewLabel(opts ...labelOptArg) *HelpLabels

func (*HelpLabels) SetAdditionalCommands added in v0.0.3

func (l *HelpLabels) SetAdditionalCommands(additionalCommands string) *HelpLabels

func (*HelpLabels) SetAddtionalHelpTopics added in v0.0.3

func (l *HelpLabels) SetAddtionalHelpTopics(addtionalHelpTopics string) *HelpLabels

func (*HelpLabels) SetAliases added in v0.0.3

func (l *HelpLabels) SetAliases(aliases string) *HelpLabels

func (*HelpLabels) SetAvailableCommands added in v0.0.3

func (l *HelpLabels) SetAvailableCommands(availableCommands string) *HelpLabels

func (*HelpLabels) SetExamples added in v0.0.3

func (l *HelpLabels) SetExamples(examples string) *HelpLabels

func (*HelpLabels) SetFlags added in v0.0.3

func (l *HelpLabels) SetFlags(flags string) *HelpLabels

func (*HelpLabels) SetGlobalFlags added in v0.0.3

func (l *HelpLabels) SetGlobalFlags(globalFlags string) *HelpLabels

func (*HelpLabels) SetUsage added in v0.0.3

func (l *HelpLabels) SetUsage(usage string) *HelpLabels

func (*HelpLabels) SetUseHelp added in v0.0.3

func (l *HelpLabels) SetUseHelp(useHelp string) *HelpLabels

type Registory

type Registory []*cobra.Command

func (*Registory) Add added in v0.0.3

func (r *Registory) Add(cmds ...*cobra.Command)

サブコマンドを追加する

func (*Registory) Bind added in v0.0.3

func (r *Registory) Bind(root *cobra.Command)

サブコマンドをRootに追加する

func (*Registory) Get added in v0.0.3

func (r *Registory) Get() []*cobra.Command

サブコマンドの一覧を取得する

Jump to

Keyboard shortcuts

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