Documentation
¶
Overview ¶
Package scan walks a directory tree, classifies files via a worker pool, and aggregates per-format statistics.
Index ¶
Constants ¶
const ( IgnoredInclude = "include" IgnoredExclude = "exclude" IgnoredOnly = "only" )
Values for Options.Ignored.
const ( HiddenInclude = "include" HiddenExclude = "exclude" )
Values for Options.Hidden.
const ( TypeText = "text" TypeBinary = "binary" TypeBoth = "both" )
Values for Options.TypeFilter.
const ( FormatsRaw = classify.FormatsRaw FormatsCanonical = classify.FormatsCanonical )
Values for Options.Formats.
const SingletonsGroup = "(singletons)"
SingletonsGroup is the format name of the pseudo-group produced by CollapseSingletons.
Variables ¶
var StatNames = []string{
"count",
"total-size", "min-size", "max-size", "avg-size",
"total-loc", "min-loc", "max-loc", "avg-loc",
}
Stat names accepted by --stats (canonical column order).
Functions ¶
func SortGroups ¶
SortGroups sorts groups in place by the given keys ("format" or a stat name) in precedence order, all in the same direction (desc when desc is true). Ties are broken by format name ascending (case-insensitive, then case-sensitive) so the output is deterministic.
Types ¶
type Group ¶
type Group struct {
Format string
Text bool
Pseudo bool // true for the "(singletons)" aggregate row (render-only)
Count int
TotalSize int64
MinSize int64
MaxSize int64
AvgSize int64 // rounded to nearest integer
HasLOC bool // LOC values are valid (text group with LOC computed)
TotalLOC int64
MinLOC int64
MaxLOC int64
AvgLOC int64 // rounded to nearest integer
}
Group is the aggregate statistics for one format.
func CollapseSingletons ¶
CollapseSingletons merges all groups with exactly one file into a single "(singletons)" pseudo-group: count is the number of merged groups, sizes are aggregated over all merged groups, and LOC values are aggregated over the text merged groups only. The input is not modified.
type Options ¶
type Options struct {
Root string // absolute path of the directory to scan
Method string // classify.MethodExt, MethodType, or MethodHybrid
Formats string // FormatsRaw or FormatsCanonical: how group names are spelled
Depth int // max directory depth below root; -1 = unlimited; root is depth 0
Exclude []string // exact base names to skip (dirs and files)
Ignored string // IgnoredInclude, IgnoredExclude, or IgnoredOnly
Hidden string // HiddenInclude or HiddenExclude
TypeFilter string // TypeText, TypeBinary, or TypeBoth
NeedLOC bool // count lines of code for text files
ListNoExt bool // collect relative paths of extensionless files
TextExts map[string]struct{}
TextMimes map[string]struct{}
Aliases map[string]string // canonical format aliases; read in FormatsCanonical only
Workers int // worker pool size; 0 = runtime.GOMAXPROCS(0)
}
Options configures a scan.
type Result ¶
type Result struct {
Root string
Method string
Summary Summary
Groups []Group
NoExtFiles []string // relative paths, sorted; filled only when Options.ListNoExt
}
Result is the outcome of a scan. Groups are ordered by format name ascending; callers apply their own sort.
type Summary ¶
type Summary struct {
Directories int // counted directories, including the root
Files int // readable files that passed traversal filters
FilesWithoutExtension int // extensionless files that passed all filters including --type
MaxDepth int // deepest counted directory (root is 0)
Symlinks int // symlinks encountered in traversed directories (never followed)
Executables int // regular files with any execute permission bit
UniqueFormats int // number of groups after the --type filter
FilesSniffed int // content-sniff operations performed
Unreadable int // directories and files skipped due to read/stat errors
}
Summary holds the tree-wide summary statistics.