ui

package
v2.4.3 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Copyright 2023 The Sigstore Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2023 The Sigstore Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2023 The Sigstore Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const TagReferenceMessage string = `` /* 361-byte string literal not displayed */

Variables

This section is empty.

Functions

func ConfirmContinue

func ConfirmContinue(ctx context.Context) error

ConfirmContinue prompts the user whether they would like to continue and returns the parsed answer.

If the user enters anything other than "y" or "Y", ConfirmContinue returns an error.

func Infof

func Infof(ctx context.Context, msg string, a ...any)

Infof logs an informational message. It works like fmt.Printf, except that it always has a trailing newline.

func RunWithTestCtx

func RunWithTestCtx(callback callbackFunc) string

RunWithTestCtx runs the provided callback in a context with the UI environment swapped out for one that allows for easy testing and captures STDOUT.

The callback has access to a function that writes to the test STDIN.

func Warnf

func Warnf(ctx context.Context, msg string, a ...any)

Warnf logs a warning message (prefixed by "WARNING:"). It works like fmt.Printf, except that it always has a trailing newline.

func WithEnv

func WithEnv(ctx context.Context, e *Env) context.Context

WithEnv adds the environment to the context.

Types

type Env

type Env struct {
	Stderr io.Writer
	Stdin  io.Reader
}

An Env is the environment that the CLI exists in.

It contains handles to STDERR and STDIN. Eventually, it will contain configuration pertaining to the current invocation (e.g., is this a terminal or not).

UI methods should be defined on an Env. Then, the Env can be changed for easy testing. The Env will be retrieved from the current application context.

type ErrInvalidInput

type ErrInvalidInput struct {
	Got     string
	Allowed string
}

func (*ErrInvalidInput) Error

func (e *ErrInvalidInput) Error() string

type ErrPromptDeclined

type ErrPromptDeclined struct{}

func (*ErrPromptDeclined) Error

func (e *ErrPromptDeclined) Error() string

type WriteFunc

type WriteFunc func(string)

Jump to

Keyboard shortcuts

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