hook

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClientPostRunHooks runHookE = Chain(
	Adapt(PrintUpdateCheck),
)

ClientPostRunHooks is the set of post-run hooks that all client commands should have applied.

View Source
var ClientPreRunHooks runHookE = Chain(
	Adapt(ApplyPorcelainLogLevel),
	Adapt(StartUpdateCheck),
)

ClientPreRunHooks is the set of pre-run hooks that all client commands should have applied.

View Source
var RemoteCmdPostRunHooks runHookE = ClientPostRunHooks

RemoteCmdPostRunHooks is the set of post-run hooks that all commands that communicate with remote servers should have applied.

View Source
var RemoteCmdPreRunHooks runHookE = Chain(
	ClientPreRunHooks,
)

RemoteCmdPreRunHooks is the set of pre-run hooks that all commands that communicate with remote servers should have applied.

Functions

func Adapt

func Adapt(hook runHook) runHookE

Adapt turns a run hook that does not return an error into one that does.

func AfterParentHook

func AfterParentHook(hook runHookE, getHook func(*cobra.Command) runHookE) runHookE

Because cobra doesn't do PersistentPreRun{,E} chaining yet (https://github.com/spf13/cobra/issues/252), this function walks upwards and finds any parent hook that should be run if the hooks were properly persistent. The complexity here is that if we are running on a child command we will first find the parent hook, and need to skip that otherwise we'll end up in an infinite loop.

func AfterParentPostRunHook

func AfterParentPostRunHook(hook runHookE) runHookE

func AfterParentPreRunHook

func AfterParentPreRunHook(hook runHookE) runHookE

func ApplyPorcelainLogLevel

func ApplyPorcelainLogLevel(cmd *cobra.Command, _ []string)

ApplyPorcelainLogLevel sets the log level of loggers running on user-facing "porcelain" commands to be zerolog.FatalLevel to reduce noise shown to users, unless the user has specifically set a valid log level with an env var.

func Chain

func Chain(hooks ...runHookE) runHookE

Run all of the passed hooks in order, stopping on and returning the first error.

func PrintUpdateCheck

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

PrintUpdateCheck is a Cobra post run hook to print the results of an update check. The message will be a non-nil pointer only if the update check succeeds and should only have visible output if the message is non-empty.

func StartUpdateCheck

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

StartUpdateCheck is a Cobra pre run hook to run an update check in the background. There should be no output if the check fails or the context is cancelled before the check can complete.

Types

This section is empty.

Jump to

Keyboard shortcuts

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