utils

package
v0.0.0-...-4df811a Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

From https://samrapdev.com/capturing-sensitive-input-with-editor-in-golang-from-the-cli/

Index

Constants

View Source
const DefaultEditor = "nano"

DefaultEditor is vim because we're adults ;)

Variables

This section is empty.

Functions

func AppendIfMissing

func AppendIfMissing(slice []string, i string) []string

AppendIfMissing function appends a string to a slice, if it is not already there

func CaptureInputFromEditor

func CaptureInputFromEditor(
	resolveEditor PreferredEditorResolver,
	extension string,
	defaultContent string,
) ([]byte, error)

CaptureInputFromEditor opens a temporary file in a text editor and returns the written bytes on success or an error on failure. It handles deletion of the temporary file behind the scenes.

func CheckSecretContent

func CheckSecretContent(name string) error

Check if secret name is SNAKE CAPITAL

func CleanTestDir

func CleanTestDir(testDir string) error

func Close

func Close(r Closer)

Close function closes anything with a `Close()` method

func CopyFile

func CopyFile(src, dst string) error

CopyFile function copies a file from `src` to `dst`

func CreateDirIfNotExist

func CreateDirIfNotExist(dirPath string) error

Creates a directory at dirPath if does not exist

func CreateFileIfNotExists

func CreateFileIfNotExists(filePath string, defaultContent string) error

Creates a file with defaultContent at filePath if it doesn't exist

func CreateTestDir

func CreateTestDir() (string, error)

func DirExists

func DirExists(filename string) bool

DirExists function returns true if `filename` exists and is a directory

func DirWalk

func DirWalk(source string, cb func(info FileInfo) error) error

func DoubleQuoteEscape

func DoubleQuoteEscape(line string) string

DoubleQuoteEscape function

func FileExists

func FileExists(filename string) bool

fileExists checks if a file exists and is not a directory before we try using it to prevent further errors.

func GetPreferredEditorFromEnvironment

func GetPreferredEditorFromEnvironment() string

GetPreferredEditorFromEnvironment returns the user's editor as defined by the `$EDITOR` environment variable, or the `DefaultEditor` if it is not set.

func OpenFileInEditor

func OpenFileInEditor(
	filename string,
	resolveEditor PreferredEditorResolver,
) error

OpenFileInEditor opens filename in a text editor.

func RemoveContents

func RemoveContents(dir string) error

RemoveContents function remove all contents of a directory

func RemoveFile

func RemoveFile(f string) error

RemoveFile function removes a file

Types

type Closer

type Closer interface {
	Close() error
}

type FileInfo

type FileInfo struct {
	FullPath string
	Path     string
	Info     os.FileInfo
	IsDir    bool
}

type PreferredEditorResolver

type PreferredEditorResolver func() string

PreferredEditorResolver is a function that returns an editor that the user prefers to use, such as the configured `$EDITOR` environment variable.

Jump to

Keyboard shortcuts

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