Documentation ¶
Index ¶
- func AddTemplateFunc(name string, tmplFunc any)
- func AddTemplateFuncs(tmplFuncs template.FuncMap)
- func ArbitraryArgs(cmd *Command, args []string) error
- func Call(name string, params ...string) (string, error)
- func CheckErr(msg any)
- func CommandLookPath() string
- func Commands(commandName string, params ...string) (string, error)
- func CompDebug(msg string, printToStdErr bool)
- func CompDebugln(msg string, printToStdErr bool)
- func CompError(msg string)
- func CompErrorln(msg string)
- func Eq(a any, b any) bool
- func ExecuteCommand(root *cobra.Command, args ...string) (output string, err error)
- func ExecuteCommandC(root *cobra.Command, args ...string) (c *cobra.Command, output string, err error)
- func ExecuteCommandWithContext(ctx context.Context, root *cobra.Command, args ...string) (output string, err error)
- func ExecuteCommandWithContextC(ctx context.Context, root *cobra.Command, args ...string) (c *cobra.Command, output string, err error)
- func Gt(a any, b any) bool
- func MarkFlagCustom(flags *pflag.FlagSet, name string, f string) error
- func MarkFlagDirname(flags *pflag.FlagSet, name string) error
- func MarkFlagFilename(flags *pflag.FlagSet, name string, extensions ...string) error
- func MarkFlagRequired(flags *pflag.FlagSet, name string) error
- func NoArgs(cmd *Command, args []string) error
- func OnInitialize(y ...func())
- func OnlyValidArgs(cmd *Command, args []string) error
- func WriteStringAndCheck(b io.StringWriter, s string)
- type Command
- type CompletionOptions
- type FParseErrWhitelist
- type PositionalArgs
- type ShellCompDirective
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddTemplateFunc ¶
AddTemplateFunc adds a template function that's available to Usage and Help template generation.
func AddTemplateFuncs ¶
AddTemplateFuncs adds multiple template functions that are available to Usage and Help template generation.
func ArbitraryArgs ¶
ArbitraryArgs never returns an error.
func Call ¶
*
- 脚本扩展 *
- 使用:
- import "github.com/deatil/lakego-doak/lakego/command"
- str, err := command.Call("lakego-admin:reset-permission") *
- @create 2021-9-25
- @author deatil
func CheckErr ¶
func CheckErr(msg any)
CheckErr prints the msg with the prefix 'Error:' and exits with error code 1. If the msg is nil, it does nothing.
func CompDebug ¶
CompDebug prints the specified string to the same file as where the completion script prints its logs. Note that completion printouts should never be on stdout as they would be wrongly interpreted as actual completion choices by the completion script.
func CompDebugln ¶
CompDebugln prints the specified string with a newline at the end to the same file as where the completion script prints its logs. Such logs are only printed when the user has set the environment variable BASH_COMP_DEBUG_FILE to the path of some file to be used.
func CompError ¶
func CompError(msg string)
CompError prints the specified completion message to stderr.
func CompErrorln ¶
func CompErrorln(msg string)
CompErrorln prints the specified completion message to stderr with a newline at the end.
func Eq ¶
Eq takes two types and checks whether they are equal. Supported types are int and string. Unsupported types will panic.
func ExecuteCommand ¶
执行脚本
func ExecuteCommandC ¶
func ExecuteCommandWithContext ¶
func ExecuteCommandWithContext(ctx context.Context, root *cobra.Command, args ...string) (output string, err error)
ctx := context.TODO()
func ExecuteCommandWithContextC ¶
func ExecuteCommandWithContextC(ctx context.Context, root *cobra.Command, args ...string) (c *cobra.Command, output string, err error)
ctx := context.TODO()
func Gt ¶
Gt takes two types and checks whether the first type is greater than the second. In case of types Arrays, Chans, Maps and Slices, Gt will compare their lengths. Ints are compared directly while strings are first parsed as ints and then compared.
func MarkFlagCustom ¶
MarkFlagCustom adds the BashCompCustom annotation to the named flag, if it exists. The bash completion script will call the bash function f for the flag.
This will only work for bash completion. It is recommended to instead use c.RegisterFlagCompletionFunc(...) which allows to register a Go function which will work across all shells.
func MarkFlagDirname ¶
MarkFlagDirname instructs the various shell completion implementations to limit completions for the named flag to directory names.
func MarkFlagFilename ¶
MarkFlagFilename instructs the various shell completion implementations to limit completions for the named flag to the specified file extensions.
func MarkFlagRequired ¶
MarkFlagRequired instructs the various shell completion implementations to prioritize the named flag when performing completion, and causes your command to report an error if invoked without the flag.
func OnInitialize ¶
func OnInitialize(y ...func())
OnInitialize sets the passed functions to be run when each command's Execute method is called.
func OnlyValidArgs ¶
OnlyValidArgs returns an error if any args are not in the list of ValidArgs.
func WriteStringAndCheck ¶
func WriteStringAndCheck(b io.StringWriter, s string)
WriteStringAndCheck writes a string into a buffer, and checks if the error is not nil.
Types ¶
type PositionalArgs ¶
type PositionalArgs = cobra.PositionalArgs
PositionalArgs
func ExactArgs ¶
func ExactArgs(n int) PositionalArgs
ExactArgs returns an error if there are not exactly n args.
func ExactValidArgs ¶
func ExactValidArgs(n int) PositionalArgs
ExactValidArgs returns an error if there are not exactly N positional args OR there are any positional args that are not in the `ValidArgs` field of `Command`
func MaximumNArgs ¶
func MaximumNArgs(n int) PositionalArgs
MaximumNArgs returns an error if there are more than N args.
func MinimumNArgs ¶
func MinimumNArgs(n int) PositionalArgs
MinimumNArgs returns an error if there is not at least N args.
func RangeArgs ¶
func RangeArgs(min int, max int) PositionalArgs
RangeArgs returns an error if the number of args is not within the expected range.
type ShellCompDirective ¶
type ShellCompDirective = cobra.ShellCompDirective
ShellCompDirective is a bit map representing the different behaviors the shell can be instructed to have once completions have been provided.
func NoFileCompletions ¶
func NoFileCompletions(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective)
NoFileCompletions can be used to disable file completion for commands that should not trigger file completions.