smash

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TreeNextChild = "├─"
	TreeLastChild = "└─"
)
View Source
const (
	GithubHomeText  = "github.com/thushan/smash"
	GithubHomeUri   = "https://github.com/thushan/smash"
	GithubLatestUri = "https://github.com/thushan/smash/releases/latest"
)
View Source
const ReportOutputTemplate = "report-*.json"

Variables

View Source
var (
	Version = "v1.0.0"
	Commit  = "none"
	Date    = "unknown"
	Time    = "nowish"
	User    = "local"
)

Functions

func PrintNerdStats added in v0.0.7

func PrintNerdStats(stats nerdstats.NerdStats, context string)

func PrintRunSummary added in v0.0.7

func PrintRunSummary(rs RunSummary, flags *Flags)

func PrintVersionInfo

func PrintVersionInfo(extendedInfo bool)

func SummariseSmashedFile added in v0.0.7

func SummariseSmashedFile(stats slicer.SlicerStats, ffs *indexer.FileFS, ms int64, duplicates *xsync.Map[string, *DuplicateFiles], empty *EmptyFiles)

Types

type App

type App struct {
	Flags     *Flags
	Session   *AppSession
	Runtime   *AppRuntime
	Summary   *RunSummary
	Output    *OutputManager
	Args      []string
	Locations []indexer.LocationFS
}

func (*App) Exec added in v0.0.4

func (app *App) Exec() error

func (*App) Export added in v0.0.7

func (app *App) Export(filePath string) (string, error)

func (*App) ExportFile added in v0.0.7

func (app *App) ExportFile(f *os.File) error

func (*App) ExportReport added in v0.0.7

func (app *App) ExportReport()

func (*App) GenerateReportOutput added in v0.0.7

func (app *App) GenerateReportOutput() ReportOutput

func (*App) PrintRunAnalysis added in v0.0.4

func (app *App) PrintRunAnalysis(ignoreEmptyFiles bool)

func (*App) Run

func (app *App) Run() error

type AppRuntime added in v0.0.4

type AppRuntime struct {
	Slicer        *slicer.Slicer
	SlicerOptions *slicer.Options
	IndexerConfig *indexer.IndexerConfig
	Files         chan *indexer.FileFS
}

type AppSession added in v0.0.3

type AppSession struct {
	Dupes     *xsync.Map[string, *DuplicateFiles]
	Fails     *xsync.Map[string, error]
	Empty     *EmptyFiles
	StartTime int64
	EndTime   int64
}

type CICapabilities added in v1.0.0

type CICapabilities struct {
	SupportsColor     bool
	SupportsBasicANSI bool
	SupportsGrouping  bool
}

CICapabilities describes what a CI environment supports

func GetCICapabilities added in v1.0.0

func GetCICapabilities() CICapabilities

GetCICapabilities returns the capabilities of the current CI environment

type DuplicateFiles added in v0.0.7

type DuplicateFiles struct {
	Files []File
	sync.RWMutex
}

type EmptyFiles added in v0.0.7

type EmptyFiles struct {
	Files []File
	sync.RWMutex
}

type EnvironmentInfo added in v1.0.0

type EnvironmentInfo struct {
	TermType      string
	IsTerminal    bool
	IsCI          bool
	IsTesting     bool
	IsContainer   bool
	ForceColor    bool
	NoColor       bool
	ShouldAnimate bool
}

EnvironmentInfo contains information about the execution environment

func DetectEnvironment added in v1.0.0

func DetectEnvironment() EnvironmentInfo

DetectEnvironment analyzes the current execution environment

type File added in v0.0.7

type File struct {
	Filename    string
	Location    string
	Path        string
	Base        string
	Hash        string
	FileSizeF   string
	FileSize    uint64
	ElapsedTime int64
	FullHash    bool
	EmptyFile   bool
}

type Flags

type Flags struct {
	OutputFile      string   `yaml:"output"`
	Base            []string `yaml:"base"`
	ExcludeDir      []string `yaml:"exclude-dir"`
	ExcludeFile     []string `yaml:"exclude-file"`
	MinSize         int64    `yaml:"min-size"`
	MaxSize         int64    `yaml:"max-size"`
	SliceThreshold  int64    `yaml:"slice-threshold"`
	SliceSize       int64    `yaml:"slice-size"`
	Slices          int      `yaml:"slices"`
	Algorithm       int      `yaml:"algorithm"`
	MaxThreads      int      `yaml:"max-threads"`
	MaxWorkers      int      `yaml:"max-workers"`
	ProgressUpdate  int      `yaml:"progress-update"`
	ShowTop         int      `yaml:"show-top"`
	DisableSlicing  bool     `yaml:"disable-slicing"`
	DisableMeta     bool     `yaml:"disable-meta"`
	DisableAutoText bool     `yaml:"disable-autotext"`
	IgnoreEmpty     bool     `yaml:"ignore-empty"`
	IgnoreHidden    bool     `yaml:"ignore-hidden"`
	IgnoreSystem    bool     `yaml:"ignore-system"`
	ShowVersion     bool     `yaml:"version"`
	ShowNerdStats   bool     `yaml:"nerd-stats"`
	Recurse         bool     `yaml:"recurse"`
	ShowDuplicates  bool     `yaml:"show-duplicates"`
	Silent          bool     `yaml:"silent"`
	HideTopList     bool     `yaml:"no-top-list"`
	HideProgress    bool     `yaml:"no-progress"`
	HideOutput      bool     `yaml:"no-output"`
	Profile         bool     `yaml:"profile"`
	Verbose         bool     `yaml:"verbose"`
}

type NoOpSpinner added in v1.0.0

type NoOpSpinner struct{}

NoOpSpinner is a spinner that does nothing (for silent/non-TTY modes)

func (*NoOpSpinner) Fail added in v1.0.0

func (n *NoOpSpinner) Fail(text string)

func (*NoOpSpinner) Stop added in v1.0.0

func (n *NoOpSpinner) Stop() error

func (*NoOpSpinner) Success added in v1.0.0

func (n *NoOpSpinner) Success(text string)

func (*NoOpSpinner) UpdateText added in v1.0.0

func (n *NoOpSpinner) UpdateText(text string)

func (*NoOpSpinner) Warning added in v1.0.0

func (n *NoOpSpinner) Warning(text string)

type OutputConfig added in v1.0.0

type OutputConfig struct {
	Silent         bool
	ShowProgress   bool
	UseColor       bool
	Verbose        bool
	GenerateReport bool
}

OutputConfig contains the resolved output configuration

type OutputManager added in v1.0.0

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

OutputManager handles all output operations respecting environment and flags

func NewOutputManager added in v1.0.0

func NewOutputManager(flags *Flags) *OutputManager

NewOutputManager creates a new output manager based on flags and environment

func (*OutputManager) IsSilent added in v1.0.0

func (om *OutputManager) IsSilent() bool

IsSilent returns true if silent mode is enabled

func (*OutputManager) IsVerbose added in v1.0.0

func (om *OutputManager) IsVerbose() bool

IsVerbose returns true if verbose output is enabled

func (*OutputManager) Print added in v1.0.0

func (om *OutputManager) Print(a ...interface{})

Print outputs a message if not in silent mode

func (*OutputManager) Printf added in v1.0.0

func (om *OutputManager) Printf(format string, a ...interface{})

Printf outputs a formatted message if not in silent mode

func (*OutputManager) Println added in v1.0.0

func (om *OutputManager) Println(a ...interface{})

Println outputs a message with newline if not in silent mode

func (*OutputManager) ShouldGenerateReport added in v1.0.0

func (om *OutputManager) ShouldGenerateReport() bool

ShouldGenerateReport returns true if report should be generated

func (*OutputManager) ShouldShowProgress added in v1.0.0

func (om *OutputManager) ShouldShowProgress() bool

ShouldShowProgress returns true if progress indicators should be shown

func (*OutputManager) StartSpinner added in v1.0.0

func (om *OutputManager) StartSpinner(spinner pterm.SpinnerPrinter, text string, writer ...*pterm.MultiPrinter) SpinnerHandle

StartSpinner creates and starts a spinner if appropriate for the environment

func (*OutputManager) VerbosePrint added in v1.0.0

func (om *OutputManager) VerbosePrint(a ...interface{})

VerbosePrint outputs a message only in verbose mode

func (*OutputManager) VerbosePrintf added in v1.0.0

func (om *OutputManager) VerbosePrintf(format string, a ...interface{})

VerbosePrintf outputs a formatted message only in verbose mode

func (*OutputManager) VerbosePrintln added in v1.0.0

func (om *OutputManager) VerbosePrintln(a ...interface{})

VerbosePrintln outputs a message with newline only in verbose mode

type ReportDuplicateSummary added in v0.0.7

type ReportDuplicateSummary struct {
	Duplicates []ReportFileSummary `json:"duplicates"`
	ReportFileSummary
}

type ReportFailSummary added in v0.0.7

type ReportFailSummary struct {
	Filename string `json:"filename"`
	Error    string `json:"error"`
}

type ReportFileBaseSummary added in v0.0.7

type ReportFileBaseSummary struct {
	Filename string `json:"filename"`
	Location string `json:"location"`
	Path     string `json:"path"`
}

type ReportFileSummary added in v0.0.7

type ReportFileSummary struct {
	ReportFileBaseSummary
	Hash     string `json:"hash"`
	Size     uint64 `json:"size"`
	FullHash bool   `json:"fullHash"`
}

type ReportFiles added in v0.0.7

type ReportFiles struct {
	Fails []ReportFailSummary      `json:"fails"`
	Empty []ReportFileBaseSummary  `json:"empty"`
	Dupes []ReportDuplicateSummary `json:"dupes"`
}

type ReportMeta added in v0.0.7

type ReportMeta struct {
	Timestamp time.Time `json:"timestamp"`
	Config    *Flags    `json:"config"`
	Version   string    `json:"version"`
	Commit    string    `json:"commit"`
	Host      string    `json:"host"`
	User      string    `json:"user"`
}

type ReportOutput added in v0.0.7

type ReportOutput struct {
	Meta     ReportMeta    `json:"_meta"`
	Analysis ReportFiles   `json:"analysis"`
	Summary  ReportSummary `json:"summary"`
}

type ReportSummary added in v0.0.7

type ReportSummary struct {
	TopFiles          []ReportTopFilesSummary `json:"top"`
	DuplicateFileSize uint64                  `json:"duplicateFileSize"`
	TotalFiles        int64                   `json:"totalFiles"`
	TotalFileErrors   int64                   `json:"totalFileFails"`
	ElapsedTime       int64                   `json:"elapsedTime"`
	UniqueFiles       int64                   `json:"uniqueFiles"`
	EmptyFiles        int64                   `json:"emptyFiles"`
	DuplicateFiles    int64                   `json:"duplicateFiles"`
}

type ReportTopFilesSummary added in v0.0.7

type ReportTopFilesSummary struct {
	Hash string `json:"hash"`
	Size uint64 `json:"size"`
}

type RunSummary

type RunSummary struct {
	DuplicateFileSizeF string
	ReportFilename     string
	TopFiles           []analysis.Item
	DuplicateFileSize  uint64
	TotalFiles         int64
	TotalFileErrors    int64
	ElapsedTime        int64
	UniqueFiles        int64
	EmptyFiles         int64
	DuplicateFiles     int64
}

type SpinnerHandle added in v1.0.0

type SpinnerHandle interface {
	UpdateText(text string)
	Success(text string)
	Fail(text string)
	Warning(text string)
	Stop() error
}

SpinnerHandle provides a common interface for spinners

Jump to

Keyboard shortcuts

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