utils

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsolutePath

func AbsolutePath(filename string) string

AbsolutePath returns the absolute path to the given file. If the filename is not already an absolute path, then we assume that it is a file path relative to the current working directory

func FileExists

func FileExists(filename string) bool

FileExists checks if a file exists and is not a directory

func FolderExists

func FolderExists(filename string) bool

FolderExists checks if a folder exists

func FolderIsEmpty

func FolderIsEmpty(filename string) (bool, error)

FolderIsEmpty checks if a folder is empty

func IsInteractive

func IsInteractive() bool

func OpenFile

func OpenFile(folder string, pattern string) (*os.File, error)

OpenFile looks inside of the given folder for a file matching the given pattern. Will return a non-nil error when either no or more than one files match. Returns the opened file otherwise.

func WrapExitError

func WrapExitError(err error) error

WrapExitError checks whether `err` is an *exec.ExitError and wraps it in a nice way Includes the Stderr output in the error message.

func WrapExitErrorf

func WrapExitErrorf(err error, message string, args ...interface{}) error

WrapExitErrorf checks whether `err` is an *exec.ExitError and wraps it in a nice way Instead of the stderr output, this function allows you to specify your own message and possible formatting arguments.

Types

type Filenames

type Filenames []string

Filenames is simply an alias for []string, but allows me to add some methods.

func FindFilesByExtInDir

func FindFilesByExtInDir(dir string, extension string) (Filenames, error)

FindFilesByExtInDir finds all files in the given directory and subdirectories that have a certain file extension. File extension must start with a '.', e.g. ".py" or ".ipynb" Returns filepaths relative to the given directory. Ignores hidden folders (folders whose names start with a '.'), but not hidden files. Also explicitly ignores `venv`, `env`. `venv.bak` and `env.bak` folders

func FindIPynbFilesIn

func FindIPynbFilesIn(dir string) (Filenames, error)

FindIPynbFilesIn finds all Jupyter Notebook (*.ipynb) files in the given directory and subdirectories. Returns their filepaths, relative to the given directory. Ignores hidden folders (folders whose names start with a '.'), but not hidden files.

func FindPythonFilesIn

func FindPythonFilesIn(dir string) (Filenames, error)

FindPythonFilesIn finds all Python (*.py) files in the given directory and subdirectories Returns their filepaths, relative to the given directory Ignores hidden folders (folders whose names start with a '.'), but not hidden files.

func (Filenames) Concat

func (names Filenames) Concat(extra Filenames) Filenames

func (Filenames) CountLoC

func (names Filenames) CountLoC() int32

func (Filenames) Filter

func (names Filenames) Filter(shouldInclude func(filename string) bool) Filenames

func (Filenames) Prefix

func (names Filenames) Prefix(dir string) Filenames

Prefix prefixes each of the filenames with a directory name. i.e. Filenames{"name.py"}.Prefix("something") becomes Filenames{"something/name.py"}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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