dirctrl

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package dirctrl is an abstraction layer for filesystem function calls.

Index

Constants

View Source
const (
	DirUnexpectedError = iota + 1
	DirUnprivilegedError
)
View Source
const OsPathSeparator = string(os.PathSeparator)

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultDirectoryCommands

type DefaultDirectoryCommands struct{}

DefaultDirectoryCommands is a placeholder struct for implemented methods of the DirectoryCommands interface.

func (*DefaultDirectoryCommands) GetAbsolutePath

func (*DefaultDirectoryCommands) GetAbsolutePath(path string) (string, error)

GetAbsolutePath gets the full path of the specified directory.

func (*DefaultDirectoryCommands) ReadDirectory

func (d *DefaultDirectoryCommands) ReadDirectory(dirname string) ([]fs.FileInfo, error)

ReadDirectory returns a list of fs.FileInfo objects from the specified directory.

func (*DefaultDirectoryCommands) ScanDirectory

func (d *DefaultDirectoryCommands) ScanDirectory(
	path string,
	callback func(dirName string),
) error

ScanDirectory iterates over each file in the path and executes a callback that is provided the name of that file.

type DefaultDirectoryController

type DefaultDirectoryController struct {
	Writer   InfoWriter
	Commands DirectoryCommands
}

DefaultDirectoryController contains a collection of methods that execute various commands on the filesystem.

func NewDefaultDirectoryController

func NewDefaultDirectoryController() *DefaultDirectoryController

NewDefaultDirectoryController creates a new instance of DefaultDirectoryController with initialized methods.

func (*DefaultDirectoryController) DirectoryIsAccessible

func (d *DefaultDirectoryController) DirectoryIsAccessible(directory string) bool

DirectoryIsAccessible determines if a directory is accessible to the current user.

func (*DefaultDirectoryController) GetAbsolutePath

func (d *DefaultDirectoryController) GetAbsolutePath(directory string) (string, error)

GetAbsolutePath gets the full path of the specified directory.

func (*DefaultDirectoryController) GetDirectoryInfo

func (d *DefaultDirectoryController) GetDirectoryInfo(directory string) (string, error)

GetDirectoryInfo returns a formatted list of files in the specified directory.

func (*DefaultDirectoryController) GetInitialDirectory

func (d *DefaultDirectoryController) GetInitialDirectory() (string, error)

GetInitialDirectory returns the path that ci was run from.

func (*DefaultDirectoryController) ScanDirectory

func (d *DefaultDirectoryController) ScanDirectory(path string, callback func(dirName string)) error

ScanDirectory iterates over each file in the path and executes a callback that is provided the name of that file.

type DefaultInfoWriter

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

DefaultInfoWriter is an InfoWriter wrapper of the tabwriter module that outputs tab formatted data to a buffer.

func NewDefaultInfoWriter

func NewDefaultInfoWriter() *DefaultInfoWriter

NewDefaultInfoWriter creates a new instance of DefaultInfoWriter.

func (*DefaultInfoWriter) Flush

func (d *DefaultInfoWriter) Flush() (string, error)

Flush clears the DefaultInfoWriter buffers and returns its contents.

func (*DefaultInfoWriter) Write

func (d *DefaultInfoWriter) Write(p []byte) (n int, err error)

Write is an implementation of the io.Writer Write function that sends data to the underlying tabwriter output stream.

type DirectoryCommands

type DirectoryCommands interface {
	ReadDirectory(dirname string) ([]fs.FileInfo, error)
	GetAbsolutePath(path string) (string, error)
	ScanDirectory(path string, callback func(dirName string)) error
}

DirectoryCommands specifies the filesystem path functions that ci uses.

type DirectoryController

type DirectoryController interface {
	GetInitialDirectory() (string, error)
	DirectoryIsAccessible(dir string) bool
	GetDirectoryInfo(dir string) (string, error)
	GetAbsolutePath(dir string) (string, error)
	ScanDirectory(path string, callback func(dirName string)) error
}

DirectoryController specifies the abstracted filesystem functions that ci uses.

type DirectoryError

type DirectoryError struct {
	Err       error
	ErrorCode int
}

DirectoryError represents an error that occurs while accessing the filesystem.

func (*DirectoryError) Error

func (d *DirectoryError) Error() string

Error returns the message for this error.

type InfoWriter

type InfoWriter interface {
	io.Writer
	Flush() (string, error)
}

InfoWriter is an extension of the default Writer interface. It is designed to abstract a wider variety of output methods.

Jump to

Keyboard shortcuts

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