cli

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Name represents the CLI name; used for invoking the CLI commands
	Name = "realm-cli"

	// Version represents the CLI version
	Version = "0.0.0" // value will be injected at build-time

)
View Source
var (
	ErrGroupNotFound = errors.New("failed to find group")
)

set of known app input errors

Functions

func CommandDisplay

func CommandDisplay(cmd string, args []flags.Arg) string

CommandDisplay returns the command display with the provided flags

func ResolveApp

func ResolveApp(ui terminal.UI, client realm.Client, filter realm.AppFilter) (realm.App, error)

ResolveApp will use the provided Realm client to resolve the app specified by the filter

func ResolveGroupID

func ResolveGroupID(ui terminal.UI, client atlas.Client) (string, error)

ResolveGroupID will use the provided MongoDB Cloud Atlas client to resolve the user's group id

Types

type Clients

type Clients struct {
	Realm        realm.Client
	Atlas        atlas.Client
	HostingAsset local.HostingAssetClient
}

Clients are the CLI clients

type Command

type Command interface {
	Handler(profile *user.Profile, ui terminal.UI, clients Clients) error
}

Command is an executable CLI command This interface maps 1:1 to Cobra's Command.RunE phase

Optionally, a Command may implement any of the other interfaces found below. The order of operations is:

  1. CommandFlagger.Flags: use this hook to register flags to parse
  2. CommandInputs.Resolve: use this hook to prompt for any flags not provided
  3. CommandPreparer.Setup: use this hook to use setup the command (e.g. create clients/services)
  4. Command.Handler: this is the command hook

At any point should an error occur, command execution will terminate and the ensuing steps will not be run

type CommandDefinition

type CommandDefinition struct {
	CommandMeta

	// Command is the command's implementation
	// If present, this value is used to specify the cobra.Command execution phases
	Command Command

	// SubCommands are the command's sub commands
	// This array is iteratively added to this Cobra command via (cobra.Command).AddCommand
	SubCommands []CommandDefinition
}

CommandDefinition is a command's definition that the CommandFactory can build a *cobra.Command from

type CommandFactory

type CommandFactory struct {
	// contains filtered or unexported fields
}

CommandFactory is a command factory

func NewCommandFactory

func NewCommandFactory() (*CommandFactory, error)

NewCommandFactory creates a new command factory

func (*CommandFactory) Build

func (factory *CommandFactory) Build(command CommandDefinition) *cobra.Command

Build builds a Cobra command from the specified CommandDefinition

func (*CommandFactory) Run

func (factory *CommandFactory) Run(cmd *cobra.Command) int

Run executes the command

func (*CommandFactory) SetGlobalFlags

func (factory *CommandFactory) SetGlobalFlags(fs *pflag.FlagSet)

SetGlobalFlags sets the global flags

func (*CommandFactory) Setup

func (factory *CommandFactory) Setup()

Setup initializes the command factory

type CommandFlags

type CommandFlags interface {
	Flags(fs *pflag.FlagSet)
}

CommandFlags provides access for commands to register local flags

type CommandInputs

type CommandInputs interface {
	Inputs() InputResolver
}

CommandInputs returns the command inputs

type CommandMeta

type CommandMeta struct {
	// Use defines how the command is used
	// This value maps 1:1 to Cobra's `Use` property
	Use string

	// Display controls how the command is described in output
	// If left blank, the command's Use value will be used instead
	Display string

	// Aliases is the list of supported aliases for the command
	// This value maps 1:1 to Cobra's `Aliases` property
	Aliases []string

	// Description is the text shown in the 'help' output of the parent command
	Description string

	// HelpText is the text shown in the 'help' output of the actual command
	// right below the command's description
	HelpText string
}

CommandMeta is the command metadata

type DisableUsage

type DisableUsage interface {
	DisableUsage() struct{}
}

DisableUsage disables the usage printing when an error occurs

type ErrAppNotFound

type ErrAppNotFound struct {
	App string
}

ErrAppNotFound is an app not found error

func (ErrAppNotFound) Error

func (err ErrAppNotFound) Error() string

type InputResolver

type InputResolver interface {
	Resolve(profile *user.Profile, ui terminal.UI) error
}

InputResolver provides access for command inputs to resolve missing data

type LinkReferrer

type LinkReferrer interface {
	ReferenceLinks() []interface{}
}

LinkReferrer provides a list of reference links that will display to the user when an error occurs

type ProjectInputs

type ProjectInputs struct {
	Project  string
	App      string
	Products []string
}

ProjectInputs are the project/app inputs for a command

func (ProjectInputs) Filter

func (i ProjectInputs) Filter() realm.AppFilter

Filter returns a realm.AppFlter based on the inputs

func (*ProjectInputs) Flags

func (i *ProjectInputs) Flags(fs *pflag.FlagSet)

Flags registers the project app input flags to the provided flag set

func (*ProjectInputs) Resolve

func (i *ProjectInputs) Resolve(ui terminal.UI, wd string, skipAppPrompt bool) error

Resolve resolves the necessary inputs that remain unset after flags have been parsed

type Suggester

type Suggester interface {
	Suggestions() []interface{}
}

Suggester provides a list of suggestions that will display to the user when an error occurs

type VersionManifestClient

type VersionManifestClient interface {
	Get(url string) (*http.Response, error)
}

VersionManifestClient is a version manifest client

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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