command

package
v1.0.1006 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTemplateFunc

func AddTemplateFunc(name string, tmplFunc any)

AddTemplateFunc adds a template function that's available to Usage and Help template generation.

func AddTemplateFuncs

func AddTemplateFuncs(tmplFuncs template.FuncMap)

AddTemplateFuncs adds multiple template functions that are available to Usage and Help template generation.

func ArbitraryArgs

func ArbitraryArgs(cmd *Command, args []string) error

ArbitraryArgs never returns an error.

func Call

func Call(name string, params ...string) (string, error)

*

  • 脚本扩展 *
  • 使用:
  • 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 CommandLookPath

func CommandLookPath() string

可执行文件的绝对路径

func Commands

func Commands(commandName string, params ...string) (string, error)

脚本文件

func CompDebug

func CompDebug(msg string, printToStdErr bool)

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

func CompDebugln(msg string, printToStdErr bool)

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

func Eq(a any, b any) bool

Eq takes two types and checks whether they are equal. Supported types are int and string. Unsupported types will panic.

func ExecuteCommand

func ExecuteCommand(root *cobra.Command, args ...string) (output string, err error)

执行脚本

func ExecuteCommandC

func ExecuteCommandC(root *cobra.Command, args ...string) (c *cobra.Command, output string, err error)

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

func Gt(a any, b any) bool

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

func MarkFlagCustom(flags *pflag.FlagSet, name string, f string) error

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

func MarkFlagDirname(flags *pflag.FlagSet, name string) error

MarkFlagDirname instructs the various shell completion implementations to limit completions for the named flag to directory names.

func MarkFlagFilename

func MarkFlagFilename(flags *pflag.FlagSet, name string, extensions ...string) error

MarkFlagFilename instructs the various shell completion implementations to limit completions for the named flag to the specified file extensions.

func MarkFlagRequired

func MarkFlagRequired(flags *pflag.FlagSet, name string) error

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 NoArgs

func NoArgs(cmd *Command, args []string) error

NoArgs returns an error if any args are included.

func OnInitialize

func OnInitialize(y ...func())

OnInitialize sets the passed functions to be run when each command's Execute method is called.

func OnlyValidArgs

func OnlyValidArgs(cmd *Command, args []string) error

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 Command

type Command = cobra.Command

脚本

type CompletionOptions

type CompletionOptions = cobra.CompletionOptions

CompletionOptions

type FParseErrWhitelist

type FParseErrWhitelist = cobra.FParseErrWhitelist

FParseErrWhitelist

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.

Jump to

Keyboard shortcuts

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