util

package
v3.13.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package cliutil contains methods used across all cli commands @todo: get rid of os.Exits and use errors instread

Index

Constants

View Source
const (
	// EnvLocal is a builtin environment, it represents your local `micro server`
	EnvLocal = "local"
	// EnvPlatform is a builtin highly available environment in the cloud,
	EnvPlatform = "platform"
)

Variables

This section is empty.

Functions

func AddEnv

func AddEnv(env Env) error

func CLIProxyAddress

func CLIProxyAddress(ctx *cli.Context) (string, error)

CLIProxyAddress returns the proxy address which should be set for the client

func CallService

func CallService(srv *registry.Service, namespace string, ctx *cli.Context) error

CallService will call a service using the arguments and flags provided in the context. It will print the result or error to stdout. If there was an error performing the call, it will be returned.

func CliError

func CliError(err error) cli.ExitCoder

CliError returns a user friendly message from error. If we can't determine a good one returns an error with code 128

func DelEnv

func DelEnv(ctx *cli.Context, envName string) error

DelEnv deletes an env from config

func FlagsToRequest

func FlagsToRequest(flags map[string][]string, req *registry.Value) (map[string]interface{}, error)

FlagsToRequest parses a set of flags, e.g {name:"Foo", "options_surname","Bar"} and converts it into a request body. If the key is not a valid object in the request, an error will be returned.

This function constructs []interface{} slices as opposed to typed ([]string etc) slices for easier testing

func FormatServiceUsage

func FormatServiceUsage(srv *registry.Service, c *cli.Context) string

FormatServiceUsage returns a string containing the service usage.

func IsBuiltInService

func IsBuiltInService(command string) bool

func IsPlatform

func IsPlatform(ctx *cli.Context) bool

func LookupService

func LookupService(ctx *cli.Context) (*registry.Service, string, error)

LookupService queries the service for a service with the given alias. If no services are found for a given alias, the registry will return nil and the error will also be nil. An error is only returned if there was an issue listing from the registry.

func Print

func Print(e Exec) func(*cli.Context) error

func SetEnv

func SetEnv(envName string) error

SetEnv selects an environment to be used.

func ShouldRenderHelp

func ShouldRenderHelp(ctx *cli.Context) bool

ShouldRenderHelp returns true if the help flag was passed

Types

type Env

type Env struct {
	Name         string
	ProxyAddress string
	Description  string
}

func GetEnv

func GetEnv(ctx *cli.Context) (Env, error)

GetEnv returns the current selected environment Does not take

func GetEnvByName

func GetEnvByName(env string) (Env, error)

func GetEnvs

func GetEnvs() ([]Env, error)

type Exec

type Exec func(*cli.Context, []string) ([]byte, error)

Jump to

Keyboard shortcuts

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