Documentation ¶
Overview ¶
Package core implements the data models and helper utilities for printing tree structure of the specified directory
By Vinit Kumar Rai <vinitrai.marshal@gmail.com>
Index ¶
- Constants
- Variables
- func FileFilterPattern(fis []os.FileInfo, pattern string, include bool) []os.FileInfo
- func Filter(eles []os.FileInfo, f filterFunc) []os.FileInfo
- func FilterInDir(fis []os.FileInfo) []os.FileInfo
- func FilterOutHidden(fis []os.FileInfo) []os.FileInfo
- func GetExtra(tree Tree, opt Options) string
- func InitAurora(enableColorOutput bool)
- type ByModTime
- type ByNameReverse
- type Colorize
- type FileFilterFunc
- type FileType
- type JSONTree
- type Options
- type Stats
- type Tree
Constants ¶
const ( FILE = 1 DIR = 2 )
Enum for FileType
Variables ¶
var ColorMap = map[string]Colorize{ "gray": colorCurry(aurora.GrayFg, false), "grayb": colorCurry(aurora.GrayFg, true), "green": colorCurry(aurora.GreenFg, false), "greenb": colorCurry(aurora.GreenFg, true), "blue": colorCurry(aurora.BlueFg, false), "blueb": colorCurry(aurora.BlueFg, true), "brown": colorCurry(aurora.BrownFg, false), "brownb": colorCurry(aurora.BrownFg, true), "red": colorCurry(aurora.RedFg, false), "redb": colorCurry(aurora.RedFg, true), "black": colorCurry(aurora.BlackFg, false), "blackb": colorCurry(aurora.BlackFg, true), "magenta": colorCurry(aurora.MagentaFg, false), "magentab": colorCurry(aurora.MagentaFg, true), "cyan": colorCurry(aurora.CyanFg, false), "cyanb": colorCurry(aurora.CyanFg, true), }
ColorMap A map of supported colors, wich uses internal partial function and returns a function of type Colorize. Uses of partial function allows us to limit the uses of Aurora's way of colorizing the string at one place and gives us the flexibility to easily switch to any other lib in future.
var FTypeIds = map[string]FileType{ "file": FILE, "dir": DIR, }
FTypeIds Map of String Name to Its FileType
var FTypeName = map[FileType]string{ FILE: "file", DIR: "dir", }
FTypeName Map of fileType to Its String name
Functions ¶
func FileFilterPattern ¶
FileFilterPattern Filter fileInfos whose filepath matched with patern. Include flag is used to control the inclusion/exclusion of matched fileinfos in the result set. eg. If include flag is true, and file path matched with given pattern, then that file info will be incuded in the result. Note: This filter will only be applied on files
func FilterInDir ¶
FilterInDir return on those file infos which are of type directory
func FilterOutHidden ¶
FilterOutHidden return on those file which are not hidden
func InitAurora ¶
func InitAurora(enableColorOutput bool)
InitAurora Utility method to initialize Aurora(ANSI color library), being used to print colorize output. Aurora Provides flag to allow enabling or disabling output
Types ¶
type ByNameReverse ¶ added in v0.1.2
ByNameReverse Sort FileInfos by name
func (ByNameReverse) Len ¶ added in v0.1.2
func (a ByNameReverse) Len() int
func (ByNameReverse) Less ¶ added in v0.1.2
func (a ByNameReverse) Less(i, j int) bool
func (ByNameReverse) Swap ¶ added in v0.1.2
func (a ByNameReverse) Swap(i, j int)
type FileType ¶
type FileType int
FileType EnumType for filetype
func GetFileType ¶
GetFileType Utility method to get fileType
func (FileType) MarshalJSON ¶
MarshalJSON Marshal FileType as JSON String
func (*FileType) UnmarshalJSON ¶
UnmarshalJSON UnMarshal FileType JSON String as FileType
type JSONTree ¶
type JSONTree struct { Name string `json:"name"` FType FileType `json:"file_type"` FStats *Stats `json:"stats,omitempty"` SubTree []JSONTree `json:"subtree"` }
JSONTree Json Representation of Tree
type Options ¶
type Options struct { IncludeHidden bool DirOnly bool ShowFullPath bool NoReport bool FollowLink bool Prune bool PrintProtection bool PrintSize bool PrintUID bool PrintGID bool PrintModTime bool SortReverse bool SortByModTime bool FileLimit int MaxLevel int16 Indent int TimeFormat string IncludePattern string ExcludePattern string OutputPath string JSONIncludeStats bool DirColor Colorize FileColor Colorize SymLinkColor Colorize TLinkColor Colorize LLinkColor Colorize PipeColor Colorize }
Options Data model to hold command line options
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions A utility method to create default Options for hitree command This is intensionally created for test cases
type Stats ¶
type Stats struct { DirCount int `json:"dir_count"` FileCount int `json:"file_count"` Size int64 `json:"size"` ModificationTime time.Time `json:"mod_time"` Permission string `json:"permission"` }
Stats Data Model to hold the File & Dir Count in the tree. Going further this will be enhanced to keep other stats like disk utilization, modification time etc at file and dir level which could be helpful in including / excluding files and directories based on these values.
type Tree ¶
Tree Data Model representing a file/directory as Root and Its childrens(in case of directory). It also contains stats of the Root, which currently only have count of all directories and files in the Root. Going further we can ustilize Stat to include few more details like space used etc.
func TraverseDir ¶
TraverseDir utility method to recursively traverse through the dir
func (Tree) AsJSONString ¶
AsJSONString ...
func (Tree) AsJSONTree ¶
AsJSONTree Utility function to return tree as json string