utils

package
v0.5.11-0...-2537224 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Copyright © 2019 Doppler <support@doppler.com>

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 © 2024 Doppler <support@doppler.com>

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 © 2020 Doppler <support@doppler.com>

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 © 2020 Doppler <support@doppler.com>

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 © 2021 Doppler <support@doppler.com>

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 Doppler <support@doppler.com>

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 © 2022 Doppler <support@doppler.com> 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 © 2023 Doppler <support@doppler.com>

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 © 2020 Doppler <support@doppler.com>

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 © 2023 Doppler <support@doppler.com>

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 © 2022 Doppler <support@doppler.com> 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 © 2022 Doppler <support@doppler.com>

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 Doppler <support@doppler.com>

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

View Source
const SupportsNamedPipes = true

Variables

View Source
var Debug = false

Debug whether we're running in debug mode

View Source
var DebugTUI = false

DebugTUI whether to log TUI debug messages to $config_dir/tui.log

View Source
var OutputJSON = false

OutputJSON whether to print OutputJSON

View Source
var Silent = false

Silent whether we should display Info messages

Functions

func CanLogDebug

func CanLogDebug() bool

CanLogDebug messages to stderr

func CanLogInfo

func CanLogInfo() bool

CanLogInfo messages to stdout

func Clamp

func Clamp[T constraints.Ordered](x, min, max T) T

func ConfigDir

func ConfigDir() string

ConfigDir DEPRECATED get configuration directory

func ConfirmationPrompt

func ConfirmationPrompt(message string, defaultValue bool) bool

ConfirmationPrompt prompt user to confirm yes/no

func Contains

func Contains[T comparable](s []T, e T) bool

func CopyToClipboard

func CopyToClipboard(text string) error

CopyToClipboard copies text to the user's clipboard

func CreateNamedPipe

func CreateNamedPipe(path string, mode uint32) error

func Cwd

func Cwd() string

Cwd current working directory of user's shell

func DotNETNameTransform

func DotNETNameTransform(name string) string

func ErrExit

func ErrExit(e error, exitCode int, messages ...string)

ErrExit prints the error and exits with the specified code

func Exists

func Exists(path string) bool

Exists whether path exists and the user has permission

func FileOwnership

func FileOwnership(path string) (int, int, error)

func FilterMap

func FilterMap[T any](origMap map[string]T, keysToSelect []string) map[string]T

FilterMap returns a new map[string]T containing origMap keys that match aginst the keysToSelect if a key in keysToSelect is not present in origMap it will be silently ignored

func GetBool

func GetBool(value string, def bool) bool

GetBool parse string into a boolean

func GetBoolFlag

func GetBoolFlag(cmd *cobra.Command, flag string) bool

GetBoolFlag gets the flag's boolean value

func GetBoolFlagIfChanged

func GetBoolFlagIfChanged(cmd *cobra.Command, flag string, def bool) bool

GetBoolFlagIfChanged gets the flag's boolean value, if specified; protects against reading an undefined flag

func GetDurationFlag

func GetDurationFlag(cmd *cobra.Command, flag string) time.Duration

GetDurationFlag gets the flag's duration

func GetDurationFlagIfChanged

func GetDurationFlagIfChanged(cmd *cobra.Command, flag string, def time.Duration) time.Duration

GetDurationFlagIfChanged gets the flag's duration, if specified; protects against reading an undefined flag

func GetFilePath

func GetFilePath(fullPath string) (string, error)

GetFilePath verify a file path and name are provided

func GetFlagIfChanged

func GetFlagIfChanged(cmd *cobra.Command, flag string, def string) string

GetFlagIfChanged gets the flag's value, if specified; protects against reading an undefined flag

func GetIntFlag

func GetIntFlag(cmd *cobra.Command, flag string, bits int) int

GetIntFlag gets the flag's int value

func GetPathFlagIfChanged

func GetPathFlagIfChanged(cmd *cobra.Command, flag string, def string) string

GetPathFlagIfChanged gets the flag's path, if specified; always returns an absolute path

func GetStdIn

func GetStdIn() (*string, error)

func HandleError

func HandleError(e error, messages ...string)

HandleError prints the error and exits with code 1

func HasDataOnStdIn

func HasDataOnStdIn() (bool, error)

func HomeDir

func HomeDir() string

HomeDir get home directory

func HostArch

func HostArch() string

HostArch the host architecture

func HostOS

func HostOS() string

HostOS the host OS

func IsDotNETSettingsFile

func IsDotNETSettingsFile(fileName string) bool

func IsMINGW64

func IsMINGW64() bool

IsMINGW64 whether the host os is running in a MINGW64-based environment like Git Bash, Cygwin, etc.

func IsMacOS

func IsMacOS() bool

IsMacOS whether the host os is macOS

func IsProcessRunning

func IsProcessRunning(p *os.Process) bool

func IsValidUUID

func IsValidUUID(s string) bool

func IsWindows

func IsWindows() bool

IsWindows whether the host os is Windows

func Log

func Log(info string)

Log info message to stderr

func LogDebug

func LogDebug(s string)

LogDebug prints a debug message to stderr

func LogDebugError

func LogDebugError(e error)

LogDebugError prints an error message to stderr when in debug mode

func LogError

func LogError(e error)

LogError prints an error message to stderr

func LogWarning

func LogWarning(s string)

LogWarning message to stderr

func MapToDotNETJSONFormat

func MapToDotNETJSONFormat(secrets map[string]string) map[string]string

func MapToEnvFormat

func MapToEnvFormat(secrets map[string]string, wrapInQuotes bool) []string

func Max

func Max[T constraints.Ordered](x, y T) T

func Min

func Min[T constraints.Ordered](x, y T) T

func ParseEnvStrings

func ParseEnvStrings(envStrings []string) map[string]string

ParseEnvStrings returns a new map[string]string created by parsing env strings (in `key=value` format).

func ParsePath

func ParsePath(path string) (string, error)

ParsePath returns an absolute path, parsing ~ . .. etc

func Print

func Print(info string)

Print output to stdout

func PrintWarning

func PrintWarning(s string)

Print output to stdout.

func RandomBase64String

func RandomBase64String(l int) string

RandomBase64String cryptographically secure random string from https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go

func RedactAuthToken

func RedactAuthToken(token string) string

RedactAuthToken returns a partially-redacted value that's safe for display

func RequireValue

func RequireValue(name string, value string)

RequireValue throws an error if a value is blank

func RestrictedFilePerms

func RestrictedFilePerms() os.FileMode

RestrictedFilePerms perms used for creating restrictied files meant to be accessible only to the user

func Retry

func Retry(attempts int, sleep time.Duration, f func() error) error

func RunCommand

func RunCommand(command []string, env []string, inFile io.Reader, outFile io.Writer, errFile io.Writer, forwardSignals bool) (*exec.Cmd, error)

RunCommand runs the specified command

func RunCommandString

func RunCommandString(command string, env []string, inFile io.Reader, outFile io.Writer, errFile io.Writer, forwardSignals bool) (*exec.Cmd, error)

RunCommandString runs the specified command string

func SelectPrompt

func SelectPrompt(message string, options []string, defaultOption string) string

SelectPrompt prompt user to select from a list of options

func UUID

func UUID() (string, error)

UUID generates a random UUID

func UpperCamel

func UpperCamel(name string) string

func WaitCommand

func WaitCommand(cmd *exec.Cmd) (int, error)

func WriteFile

func WriteFile(filename string, data []byte, perm os.FileMode) error

WriteFile atomically writes data to a file named by filename.

func WriteTempFile

func WriteTempFile(name string, data []byte, perm os.FileMode) (string, error)

WriteTempFile writes data to a unique temp file and returns the file name

Types

type StopRetry

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

StopRetry indicates to stop attempting retries. wraps an error

func StopRetryError

func StopRetryError(err error) StopRetry

Jump to

Keyboard shortcuts

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