scan

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package scan walks a directory tree, classifies files via a worker pool, and aggregates per-format statistics.

Index

Constants

View Source
const (
	IgnoredInclude = "include"
	IgnoredExclude = "exclude"
	IgnoredOnly    = "only"
)

Values for Options.Ignored.

View Source
const (
	HiddenInclude = "include"
	HiddenExclude = "exclude"
)

Values for Options.Hidden.

View Source
const (
	TypeText   = "text"
	TypeBinary = "binary"
	TypeBoth   = "both"
)

Values for Options.TypeFilter.

View Source
const (
	FormatsRaw       = classify.FormatsRaw
	FormatsCanonical = classify.FormatsCanonical
)

Values for Options.Formats.

View Source
const SingletonsGroup = "(singletons)"

SingletonsGroup is the format name of the pseudo-group produced by CollapseSingletons.

Variables

View Source
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 IsLOCStat

func IsLOCStat(name string) bool

IsLOCStat reports whether name is one of the LOC stat names.

func SortGroups

func SortGroups(groups []Group, keys []string, desc bool)

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

func CollapseSingletons(groups []Group) []Group

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.

func Scan

func Scan(opts Options) (*Result, error)

Scan walks opts.Root and returns aggregated statistics. It returns an error only if the root itself cannot be read; unreadable entries below the root are counted in Summary.Unreadable instead.

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.

Jump to

Keyboard shortcuts

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