Documentation ¶
Overview ¶
From https://samrapdev.com/capturing-sensitive-input-with-editor-in-golang-from-the-cli/
Index ¶
- Constants
- func AppendIfMissing(slice []string, i string) []string
- func CaptureInputFromEditor(resolveEditor PreferredEditorResolver, extension string, defaultContent string) ([]byte, error)
- func CheckSecretContent(name string) error
- func CleanTestDir(testDir string) error
- func Close(r Closer)
- func CopyFile(src, dst string) error
- func CreateDirIfNotExist(dirPath string) error
- func CreateFileIfNotExists(filePath string, defaultContent string) error
- func CreateTestDir() (string, error)
- func DirExists(filename string) bool
- func DirWalk(source string, cb func(info FileInfo) error) error
- func DoubleQuoteEscape(line string) string
- func FileExists(filename string) bool
- func GetPreferredEditorFromEnvironment() string
- func OpenFileInEditor(filename string, resolveEditor PreferredEditorResolver) error
- func RemoveContents(dir string) error
- func RemoveFile(f string) error
- type Closer
- type FileInfo
- type PreferredEditorResolver
Constants ¶
const DefaultEditor = "nano"
DefaultEditor is vim because we're adults ;)
Variables ¶
This section is empty.
Functions ¶
func AppendIfMissing ¶
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 ¶
Check if secret name is SNAKE CAPITAL
func CleanTestDir ¶
func CreateDirIfNotExist ¶
Creates a directory at dirPath if does not exist
func CreateFileIfNotExists ¶
Creates a file with defaultContent at filePath if it doesn't exist
func CreateTestDir ¶
func FileExists ¶
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 ¶
RemoveContents function remove all contents of a directory
Types ¶
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.