util

package
v1.1.5-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const AutoDownloadFolderPerm = 0755

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 Fatal = fatalError
View Source
var LoggingMode = logger.LogModeDefault
View Source
var ShutdownSignals = []os.Signal{
	os.Interrupt,
	syscall.SIGTERM,
}
View Source
var SystemManagerKey = contextKey{/* contains filtered or unexported fields */}

Functions

func Adapt added in v1.1.2

func Adapt(hook runHook) runHookE

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

func AfterParentHook added in v1.1.2

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 added in v1.1.2

func AfterParentPostRunHook(hook runHookE) runHookE

func AfterParentPreRunHook added in v1.1.2

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 added in v1.1.2

func Chain(hooks ...runHookE) runHookE

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

func CheckVersion

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

func DownloadResultsHandler

func DownloadResultsHandler(
	ctx context.Context,
	cmd *cobra.Command,
	jobID string,
	downloadSettings *cliflags.DownloaderSettings,
) error

func EnsureValidVersion

func EnsureValidVersion(ctx context.Context, clientVersion, serverVersion *models.BuildVersionInfo) error

func ExecuteJob

func ExecuteJob(ctx context.Context,
	j *model.Job,
	runtimeSettings *cliflags.RunTimeSettingsWithDownload,
) (*model.Job, error)

func FakeFatalErrorHandler

func FakeFatalErrorHandler(cmd *cobra.Command, msg error, code int)

FakeFatalErrorHandler captures the error for testing, responsibility of the test to handle the exit (if any) NOTE: If your test is not idempotent, you can cause side effects (the underlying function will continue to run) Returned as text JSON to wherever RootCmd is printing.

func GetAPIClient

func GetAPIClient(ctx context.Context) *client.APIClient

func GetAPIClientV2

func GetAPIClientV2(ctx context.Context) *clientv2.Client

func GetCleanupManager

func GetCleanupManager(ctx context.Context) *system.CleanupManager

func GetDefaultJobFolder

func GetDefaultJobFolder(jobID string) string

func Logs

func Logs(cmd *cobra.Command, jobID string, follow, history bool) error

func PrintUpdateCheck added in v1.1.2

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 ReadFromStdinIfAvailable

func ReadFromStdinIfAvailable(cmd *cobra.Command) ([]byte, error)

func StartUpdateCheck added in v1.1.2

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

type Msg

type Msg struct {
	Tag          uint8
	Data         string
	ErrorMessage string
}

type Versions added in v1.1.2

type Versions struct {
	ClientVersion *models.BuildVersionInfo `json:"clientVersion,omitempty"`
	ServerVersion *models.BuildVersionInfo `json:"serverVersion,omitempty"`
	LatestVersion *models.BuildVersionInfo `json:"latestVersion,omitempty"`
	UpdateMessage string                   `json:"updateMessage,omitempty"`
}

func GetAllVersions added in v1.1.2

func GetAllVersions(ctx context.Context) (Versions, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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