cli

package
v0.0.74 Latest Latest
Warning

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

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

Documentation

Overview

Package cli contains utility for the cli

Package cli contains utility for the cli

Index

Constants

This section is empty.

Variables

View Source
var (
	// PrimaryColor is the primary color for the cli.
	PrimaryColor = lipgloss.Color("#00BBBE")
	// SecondaryColor is the secondary color for the cli.
	SecondaryColor = lipgloss.Color("#59CFA8")
	// AccentColor is the accent color for the cli.
	AccentColor = lipgloss.Color("#3D34E0")
	// WhiteColor is the white color for the cli.
	WhiteColor = lipgloss.Color("#FFFFFF")
	// BlackColor is the black color for the cli.
	BlackColor = lipgloss.Color("#000000")
)

Color Palette

View Source
var (
	// DefaultBannerWidth is the default width for a banner
	DefaultBannerWidth = 80
	// Header is the style to use for headers
	Header = lipgloss.NewStyle().
			Bold(true).
			Foreground(PrimaryColor).
			PaddingTop(1).
			PaddingBottom(1).
			PaddingLeft(1).
			PaddingRight(1).
			MaxWidth(80)
	WarningBanner = lipgloss.NewStyle().
					Bold(true).
					Background(BlackColor).
					Foreground(WhiteColor).
					BorderForeground(AccentColor).
					PaddingTop(2).
					PaddingBottom(2).
					PaddingLeft(4).
					PaddingRight(4).
					Width(DefaultBannerWidth)
	// SuccessBanner is the style to use for a success banner
	SuccessBanner = lipgloss.NewStyle().
					Bold(true).
					Background(AccentColor).
					Foreground(WhiteColor).
					PaddingTop(1).
					PaddingBottom(1).
					PaddingLeft(4).
					PaddingRight(4).
					Width(DefaultBannerWidth)
)

Banner styles

View Source
var (
	CursorStyle = lipgloss.NewStyle().Foreground(SecondaryColor)
)

Common styles

Functions

func ConcatenateAndWrap

func ConcatenateAndWrap(input string, maxLen int) string

ConcatenateAndWrap takes a string and a maximum line length (maxLen), then outputs the string as a multiline string where each line does not exceed maxLen characters.

func EnsureCredentials

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

EnsureCredentials is a PreRunE function to ensure that the user has valid credentials, opening a browser for login if needed.

func ExitNicelyOnError

func ExitNicelyOnError(err error, userMsg string)

ExitNicelyOnError print a message and exit with the right code

func GRPCClientWrapRunE

func GRPCClientWrapRunE(
	runEFunc func(ctx context.Context, cmd *cobra.Command, args []string, c *grpc.ClientConn) error,
) func(cmd *cobra.Command, args []string) error

GRPCClientWrapRunE is a wrapper for cobra commands that sets up the grpc client and context

func GetAppContext

func GetAppContext(ctx context.Context, v *viper.Viper) (context.Context, context.CancelFunc)

GetAppContext is a helper for getting the cmd app context

func GetAppContextWithTimeoutDuration

func GetAppContextWithTimeoutDuration(ctx context.Context, v *viper.Viper, tout int) (context.Context, context.CancelFunc)

GetAppContextWithTimeoutDuration is a helper for getting the cmd app context with a custom timeout

func GetDefaultCLIConfigPath

func GetDefaultCLIConfigPath() string

GetDefaultCLIConfigPath returns the default path for the CLI config file Returns an empty string if the path cannot be determined

func GetNameAndOwnerFromRepository

func GetNameAndOwnerFromRepository(repository string) (string, string)

GetNameAndOwnerFromRepository returns the owner and name from a repository name in the format owner/name

func GetRelevantCLIConfigPath

func GetRelevantCLIConfigPath(v *viper.Viper) string

GetRelevantCLIConfigPath returns the relevant CLI config path. It will return the first path that exists from the following: 1. The path specified in the config flag 2. The local config.yaml file 3. The default CLI config path

func GetRepositoryName

func GetRepositoryName(owner, name string) string

GetRepositoryName returns the repository name in the format owner/name

func GrpcForCommand

func GrpcForCommand(cmd *cobra.Command, v *viper.Viper) (*grpc.ClientConn, error)

GrpcForCommand is a helper for getting a testing connection from cobra flags

func IsYAMLFileAndNotATest added in v0.0.68

func IsYAMLFileAndNotATest(path string) bool

IsYAMLFileAndNotATest checks if a file is a YAML file and not a test file

func Login

func Login(
	ctx context.Context,
	cmd *cobra.Command,
	cfg *clientconfig.Config,
	extraScopes []string,
	skipBroswer bool,
) (*oidc.Tokens[*oidc.IDTokenClaims], error)

Login is a helper function to handle the login process and return the access token

func LoginAndSaveCreds

func LoginAndSaveCreds(ctx context.Context, cmd *cobra.Command, clientConfig *clientconfig.Config) (string, error)

LoginAndSaveCreds runs a login flow for the user, opening a browser if needed. If the credentials need to be refreshed, the new credentials will be saved for future use.

func MaybeRenderMarkdown

func MaybeRenderMarkdown(payload string) string

MaybeRenderMarkdown tries to render the given string as markdown. In case of error it silently ignores the error and returns the string as-is.

func MessageAndError

func MessageAndError(msg string, err error) error

MessageAndError prints a message and returns an error.

func MultiSelect

func MultiSelect(choices []string) ([]string, error)

MultiSelect implements the necessary logic to implement an interactive multi-select menu for the CLI.

Given a list of string as choices, returns those interactively selected by the user.

func PrintYesNoPrompt

func PrintYesNoPrompt(cmd *cobra.Command, promptMsg, confirmMsg, fallbackMsg string, defaultYes bool) bool

PrintYesNoPrompt prints a yes/no prompt to the user and returns false if the user did not respond with yes or y

func RenderMarkdown

func RenderMarkdown(payload string) (string, error)

RenderMarkdown renders the given string as markdown.

func SetProviderConfig

func SetProviderConfig(
	ctx context.Context,
	provCli minderv1.ProvidersServiceClient,
	project, providerName string,
	serde *ProviderConfigUnion,
) error

SetProviderConfig sets the provider configuration in the minder service

func ValidateRepositoryName

func ValidateRepositoryName(repository string) error

ValidateRepositoryName checks if a repository name is valid

Types

type ErrWrappedCLIError

type ErrWrappedCLIError struct {
	Message string
	Err     error
}

ErrWrappedCLIError is an error that wraps another error and provides a message used from within the CLI

func (*ErrWrappedCLIError) Error

func (e *ErrWrappedCLIError) Error() string

type ProviderConfigUnion

type ProviderConfigUnion struct {
	*minderv1.ProviderConfig
	//nolint:lll
	GitHub *minderv1.GitHubProviderConfig `json:"github,omitempty" yaml:"github" mapstructure:"github" validate:"required"`
	//nolint:lll
	GitHubApp *minderv1.GitHubAppProviderConfig `json:"github_app,omitempty" yaml:"github_app" mapstructure:"github_app" validate:"required"`
}

ProviderConfigUnion is a union type for the different provider configurations this is a temporary kludge until we can autogenerate the possible attributes

func GetProviderConfig

func GetProviderConfig(
	ctx context.Context,
	provCli minderv1.ProvidersServiceClient,
	project, providerName string,
) (*ProviderConfigUnion, error)

GetProviderConfig retrieves the provider configuration from the minder service

Directories

Path Synopsis
Package table contains utilities for rendering tables
Package table contains utilities for rendering tables
layouts
Package layouts defines the available table layouts
Package layouts defines the available table layouts
simple
Package simple contains a simple table
Package simple contains a simple table
Package useragent contains utilities for setting up the CLI's user agent
Package useragent contains utilities for setting up the CLI's user agent

Jump to

Keyboard shortcuts

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