Documentation ¶
Overview ¶
Copyright © 2019 Portworx
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 © 2019 Portworx ¶
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 2018 Portworx ¶
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
- Variables
- func AddArray(t *tabby.Tabby, name string, strArr []string)
- func AddMap(t *tabby.Tabby, name string, strMap map[string]string)
- func CommaStringToStringMap(s string) (map[string]string, error)
- func Eprintf(format string, args ...interface{})
- func FixCommaBasedStringSliceInput(params, args []string) []string
- func FromError(err error) *status.Status
- func GetAclFromString(s string) (string, api.Ownership_AccessType, error)
- func GetAclMapFromString(s string) (map[string]api.Ownership_AccessType, error)
- func GetFormattedOutput(in FormatOutput) (string, error)
- func GetRandomName(prefix string) string
- func InKubectlPluginMode() bool
- func IsErrorNotFound(err error) bool
- func IsErrorPermissionDenied(err error) bool
- func IsFileExists(fileName string) bool
- func ListContains(list []string, s string) bool
- func ListContainsSubString(list []string, s string) bool
- func ListHaveMatch(list, match []string) (string, bool)
- func ListMatchGlob(rules []string, s string) bool
- func MatchGlob(rule, s string) bool
- func NewTabby() *tabby.Tabby
- func PrintFormatted(in FormatOutput) error
- func PrintJson(obj interface{})
- func PrintPxErrorMessagef(err error, format string, args ...string)
- func PrintYaml(obj interface{})
- func Printf(format string, args ...interface{})
- func PxError(err error) error
- func PxErrorMessage(err error, msg string) error
- func PxErrorMessagef(err error, format string, args ...string) error
- func RectifyErrorMessage(msg string) string
- func SdkStatusToPrettyString(status api.Status) string
- func StringContainsAnyFromList(s string, list []string) bool
- func StringMapToCommaString(labels map[string]string) string
- func ToJson(obj interface{}) (string, error)
- func ToYaml(obj interface{}) (string, error)
- func ValidateEndpoint(endpoint string) (string, error)
- func WaitFor(timeout time.Duration, period time.Duration, f func() (bool, error)) error
- type BaseFormatOutput
- func (bfo *BaseFormatOutput) DefaultFormat() (string, error)
- func (bfo *BaseFormatOutput) GetFormat() string
- func (bfo *BaseFormatOutput) JsonFormat() (string, error)
- func (bfo *BaseFormatOutput) SetFormat(typeOfOutput string)
- func (bfo *BaseFormatOutput) WideFormat() (string, error)
- func (bfo *BaseFormatOutput) YamlFormat() (string, error)
- type DefaultFormatOutput
- type FormatOutput
- type SigIntManager
Constants ¶
const ( FORMAT_WIDE = "wide" FORMAT_JSON = "json" FORMAT_YAML = "yaml" )
const ( EvInKubectlPluginMode = "PXC_KUBECTL_PLUGIN_MODE" EvPxcToken = "PXC_TOKEN" EvPortworxServiceNamespace = "PXC_PORTWORX_SERVICE_NAMESPACE" EvPortworxServiceName = "PXC_PORTWORX_SERVICE_NAME" EvPortworxServicePort = "PXC_PORTWORX_SERVICE_PORT" )
const ( DefaultPort = "9020" TimeFormat = "Jan 2 15:04:05 UTC 2006" )
const ( Ki = 1024 Mi = 1024 * Ki Gi = 1024 * Mi Ti = 1024 * Gi )
Variables ¶
var ( // Stdout points to the output buffer to send screen output Stdout io.Writer = os.Stdout // Stderr points to the output buffer to send errors to the screen Stderr io.Writer = os.Stderr )
var (
ErrInvalidEndpoint = errors.New("Invalid Endpoint")
)
Functions ¶
func CommaStringToStringMap ¶
CommaStringToStringMap returns a string map composed of the k=v comma separated values in the string
func Eprintf ¶
func Eprintf(format string, args ...interface{})
Eprintf prints the errors to the output buffer Stderr. It is equal to fmt.Fprintf(util.Stderr, format, args)
func FixCommaBasedStringSliceInput ¶ added in v0.22.0
FixCommaBasedStringSliceInput fixes params by combining successive values such that they are recovered due to strings split on a comma during CLI parsing.
Background: Cobra CLI framework splits the input values on a string slice based on comma. https://github.com/spf13/pflag/blob/9a97c102cda95a86cec2345a6f09f55a939babf5/string_slice.go#L85 Therefore, a custom formatted input is unable to use comma in the format. This command joins the split components.
Recommendation: Do not use comma in the value to avoid use of such custom parsing logic.
func GetAclFromString ¶ added in v0.21.4
func GetAclFromString(s string) (string, api.Ownership_AccessType, error)
GetAclFromString takes values like group1:r or group2:w and breaks them returning the group name and the access type.
func GetAclMapFromString ¶ added in v0.21.4
func GetAclMapFromString(s string) (map[string]api.Ownership_AccessType, error)
GetAclMapFromString takes a comma separated string of acl names and their types, and returns a map of the names to their access types
func GetFormattedOutput ¶ added in v0.21.3
func GetFormattedOutput(in FormatOutput) (string, error)
GetFormattedOutput returns the formatted output
func GetRandomName ¶ added in v0.21.3
Generate random string with the given prefix, by appending random numbers.
func InKubectlPluginMode ¶ added in v0.23.0
func InKubectlPluginMode() bool
InKubectlPluginMode returns true if running as a plugin to kubectl
func IsErrorNotFound ¶ added in v0.28.0
IsErrorNotFound returns if the given error is due to not found
func IsErrorPermissionDenied ¶ added in v0.28.0
func IsFileExists ¶ added in v0.21.3
IsFileExists returns true if the file exists else false
func ListContains ¶
ListContains returns true when string s is found in the list
func ListContainsSubString ¶ added in v0.21.3
ListContains returns true when string s is found in the list
func ListHaveMatch ¶
ListsHaveMatch returns the string and true if any one string is found in both lists
func ListMatchGlob ¶ added in v0.31.1
ListMatchGlob returns true if the string matches any of the rules
func MatchGlob ¶ added in v0.31.1
MatchGlob determines if the rules apply to string s rule can be: '*' - match all '*xxx' - ends with xxx 'xxx*' - starts with xxx '*xxx*' - contains xxx
func NewTabby ¶
NewTabby is used to return a tabbing object set to the value of Stdout in the util package
func PrintFormatted ¶ added in v0.21.3
func PrintFormatted(in FormatOutput) error
Print the formatted output to stdout In case of any error, just return the error
func PrintPxErrorMessagef ¶
PrintPxErrorMessagef prints the Portworx error message to Stderr
func Printf ¶
func Printf(format string, args ...interface{})
Printf is just like fmt.Printf except that it send the output to Stdout. It is equal to fmt.Fprintf(util.Stdout, format, args)
func PxErrorMessage ¶
PxErrorMessage returns an error composed of the gRPC error status message and the message provided.
func PxErrorMessagef ¶
PxErrorMessagef is like PxErrorMessage, but also adds formatted string support
func RectifyErrorMessage ¶ added in v0.28.0
RectifyErrorMessage changes cryptic messages
func SdkStatusToPrettyString ¶ added in v0.22.0
SdkStatusToPrettyString returns a human readable version of the Sdk Status
func StringContainsAnyFromList ¶ added in v0.21.3
func StringMapToCommaString ¶
StringMapToCommaString returns a comma separated k=v as a single string
func ValidateEndpoint ¶ added in v0.21.3
ValidateEndpoint will valid whether given endpoint is a valid. Following validation will be done on the endpoint: 1. Check whether the host part (IP or hostname) is valid 2. Check whether port number is present in the endpoint, If not add Default_port.
Types ¶
type BaseFormatOutput ¶ added in v0.21.3
type BaseFormatOutput struct {
FormatType string
}
func (*BaseFormatOutput) DefaultFormat ¶ added in v0.21.3
func (bfo *BaseFormatOutput) DefaultFormat() (string, error)
DefaultFormat just returns the Desc
func (*BaseFormatOutput) GetFormat ¶ added in v0.21.3
func (bfo *BaseFormatOutput) GetFormat() string
GetFormat returns the format type set
func (*BaseFormatOutput) JsonFormat ¶ added in v0.21.3
func (bfo *BaseFormatOutput) JsonFormat() (string, error)
JsonFormat just returns the DefaultFormat
func (*BaseFormatOutput) SetFormat ¶ added in v0.21.3
func (bfo *BaseFormatOutput) SetFormat(typeOfOutput string)
SetFormat takes in as input the type of Formatting needed. Currently recoganized values are "wide", "json" and "yaml". Any other string including "" will end up with DefaultFormat.
func (*BaseFormatOutput) WideFormat ¶ added in v0.21.3
func (bfo *BaseFormatOutput) WideFormat() (string, error)
WideFormat just returns the DefaultFormat
func (*BaseFormatOutput) YamlFormat ¶ added in v0.21.3
func (bfo *BaseFormatOutput) YamlFormat() (string, error)
YamlFormat just returns the YamlFormat
type DefaultFormatOutput ¶ added in v0.21.3
type DefaultFormatOutput struct { BaseFormatOutput `json:"-" yaml:"-"` Cmd string `json:"cmd,omitempty" yaml:"cmd,omitempty"` Desc string `json:"desc,omitempty" yaml:"desc,omitempty"` Id []string `json:"id,omitempty" yaml:"id,omitempty"` }
func (*DefaultFormatOutput) DefaultFormat ¶ added in v0.21.3
func (dfo *DefaultFormatOutput) DefaultFormat() (string, error)
DefaultFormat returns the Desc
func (*DefaultFormatOutput) JsonFormat ¶ added in v0.21.3
func (dfo *DefaultFormatOutput) JsonFormat() (string, error)
JsonFormat returns the object in json format
func (*DefaultFormatOutput) WideFormat ¶ added in v0.21.3
func (dfo *DefaultFormatOutput) WideFormat() (string, error)
WideFormat returns the DefaultFormat
func (*DefaultFormatOutput) YamlFormat ¶ added in v0.21.3
func (dfo *DefaultFormatOutput) YamlFormat() (string, error)
YamlFormat returns the object in yaml format
type FormatOutput ¶ added in v0.21.3
type FormatOutput interface { // SetFormat takes in as input the type of Formatting needed. // Currently recoganized values are "wide", "json" and "yaml". // Any other string including "" will end up with DefaultFormat. SetFormat(typeOfFormatting string) // GetFormat returns the format type set GetFormat() string // DefaultFormat formats the output as a regular string // This is called when either "wide", "yaml" or "json" is not set DefaultFormat() (string, error) // WideFormat formats the object in the "wide" format WideFormat() (string, error) // YamlFormat formats the object in the "yaml" format YamlFormat() (string, error) // JsonFormat formats the object in the "json" format JsonFormat() (string, error) }
FormatOutput is the interface used to ensure proper formatting
type SigIntManager ¶ added in v0.29.0
type SigIntManager struct {
// contains filtered or unexported fields
}
func NewSigIntManager ¶ added in v0.29.0
func NewSigIntManager(handler func()) *SigIntManager
func (*SigIntManager) Start ¶ added in v0.29.0
func (s *SigIntManager) Start() error
func (*SigIntManager) Stop ¶ added in v0.29.0
func (s *SigIntManager) Stop() error