ls

package
v6.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2019 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package ls implements formatting tools to list files like the Linux ls tool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileInfo

type FileInfo struct {
	Name          string
	Mode          os.FileMode
	Rdev          uint64
	UID, GID      uint32
	Size          int64
	MTime         time.Time
	SymlinkTarget string
}

Since `os.FileInfo` is an interface, it is difficult to tweak some of its internal values. For example, replacing the starting directory with a dot. `extractImportantParts` populates our own struct which we can modify at will before printing.

func FromOSFileInfo

func FromOSFileInfo(path string, fi os.FileInfo) FileInfo

func (FileInfo) PrintableName

func (fi FileInfo) PrintableName() string

Name returns a printable file name.

type LongStringer

type LongStringer struct {
	Human bool
	Name  Stringer
}

LongStringer is a Stringer that returns the file info formatted in `ls -l` long format.

func (LongStringer) FileString

func (ls LongStringer) FileString(fi FileInfo) string

FileString implements Stringer.FileString.

type NameStringer

type NameStringer struct{}

NameStringer is a Stringer implementation that just prints the name.

func (NameStringer) FileString

func (ns NameStringer) FileString(fi FileInfo) string

FileString implements Stringer.FileString and just returns fi's name.

type QuotedStringer

type QuotedStringer struct{}

QuotedStringer is a Stringer that returns the file name surrounded by qutoes with escaped control characters.

func (QuotedStringer) FileString

func (qs QuotedStringer) FileString(fi FileInfo) string

FileString returns the name surrounded by quotes with escaped control characters.

type Stringer

type Stringer interface {
	// FileString formats a FileInfo.
	FileString(fi FileInfo) string
}

Stringer provides a consistent way to format FileInfo.

Jump to

Keyboard shortcuts

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