cliutil

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: Apache-2.0 Imports: 27 Imported by: 6

Documentation

Overview

Package cliutil provides helpers for building Command Lines.

Index

Constants

View Source
const (
	// OutputJSON encodes the output as JSON.
	OutputJSON = "json"
)

Variables

This section is empty.

Functions

func New

func New(logger *zap.Logger, rootCmd *cobra.Command) (Factory, *Config)

New returns a new Factory using defaults to authenticate against the Platform API.

Types

type APIClient

type APIClient interface {
	Accounts() indentv1.AccountAPIClient
	Blocks() indentv1.BlockAPIClient
	Petitions() indentv1.PetitionAPIClient
	Resources() indentv1.ResourceAPIClient
	Tokens() indentv1.TokenAPIClient
	Webhooks() indentv1.WebhookAPIClient
}

APIClient returns type specific clients.

func NewAPIClient

func NewAPIClient(ctx context.Context, f Factory) (APIClient, error)

NewAPIClient creates a client configured with f.

type Config

type Config struct {

	// Environment is the environment to use with the CLI.
	*Environment `mapstructure:"ENVIRONMENT" yaml:"environment"`

	// Space is the name of the space being used with the CLI.
	Space string `mapstructure:"SPACE" yaml:"space"`

	// Staging specifies that the staging environment should be used.
	Staging bool `mapstructure:"STAGING" yaml:"staging"`

	// JSONKeyFile specifies a path to a Google Developers service account
	// JSON key file. If none, then a standard oauth token is expected.
	JSONKeyFile string `mapstructure:"JSON_KEY_FILE" yaml:"jsonKeyFile"`

	// Verbose specifies that the logger should include debug messages and additional context.
	Verbose bool `mapstructure:"VERBOSE" yaml:"verbose"`

	// Headless specifies that the CLI should not open a browser login window.
	Headless bool `mapstructure:"HEADLESS" yaml:"headless"`
	// contains filtered or unexported fields
}

Config shared by all commands of the CLI.

func NewConfig

func NewConfig(logger *zap.Logger) *Config

NewConfig configures viper and returns a Config defaulting to the production environment.

type Environment

type Environment struct {
	// Name of the environment.
	Name string `yaml:"name"`

	// Target is the gRPC endpoint dialed to connect.
	Target string `yaml:"target"`

	// OAuth contains the configuration used to authenticate with OAuth2.
	OAuth *oauth2.Config `yaml:"oauth"`
}

Environment specifies the Indent environment being connected to.

type Factory

type Factory interface {
	// Setup readies the factory for use.
	Setup()

	// Logger returns a zap.Logger for logging messages in the CLI.
	Logger() *zap.Logger

	// Config returns the global configuration of the CLI.
	Config() *Config

	// WriteConfig writes the current configuration to disk.
	WriteConfig()

	// Store returns a token Store.
	Store() oauthutil.Store

	// OutputJSON writes the given proto.Message to stdout as JSON.
	OutputJSON(proto.Message)

	// API returns an APIClient configured to use the Platform API.
	API(context.Context) APIClient

	// Resources returns all the Resources in the space.
	Resources(ctx context.Context, view string) *indentv1.ListResourcesResponse

	// SelectResource uses an interactive prompt to select a resource.
	SelectResource(ctx context.Context, view string) (selected *auditv1.Resource)

	// CurrentUser returns a Resource representing the currently logged-in user.
	CurrentUser(context.Context) *auditv1.Resource

	// IsLoggedIn returns whether credentials and are active or not
	IsLoggedIn(context.Context) bool

	// AppConfigName returns the ConfigName for the space.
	AppConfigName(context.Context) string
}

Factory provides shared configuration used across the CLI.

type Select added in v1.0.2

type Select[A proto.Message] struct {
	Select promptui.Select
	// contains filtered or unexported fields
}

Select manages the lifecycle of a select prompt.

func NewSelect added in v1.0.2

func NewSelect[A proto.Message](items []A) (*Select[A], error)

NewSelect is a helper for interactive selection from a list.

func (*Select[A]) Run added in v1.0.2

func (s *Select[A]) Run() (a A, err error)

Run the select prompt.

Jump to

Keyboard shortcuts

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