gomeasure

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package gomeasure contains the business logic or the main logic of the software

This allows any driver (e.g. a CLI) to simply call functions to get things done. (Separation of concerns).

Index

Constants

View Source
const (
	// MeasureFile counts the number of files in a project or directory
	MeasureFile measureAction = iota

	// MeasureLine counts the number of lines in a file
	MeasureLine

	// MeasureCharacter counts the number of characters in a file (files inside a folder)
	MeasureCharacter
)

Variables

This section is empty.

Functions

func PrettyPrint added in v0.3.2

func PrettyPrint(lines []string) string

PrettyPrint prints rows of lines in a tabular format. Each line is a row and each column of line is separated by a tab.

Types

type Config added in v0.3.1

type Config struct {
	// glob expression of files to be included on the command count process
	IncludedFiles string `json:"include"`

	// glob expression of files to be excluded on the command count process
	ExcludedFiles string `json:"exclude"`

	// bool value to weather to count empty lines in the command count process
	ShouldCountEmpty bool `json:"empty_lines"`

	// number of concurrent workers used to read files and count them
	WorkersCount int `json:"workers"`

	// IsVerbose determines if the program should print the progress of the command count process
	IsVerbose bool `json:"verbose"`
}

Config is the configuration struct for gomeasure.

func NewConfig added in v0.3.1

func NewConfig() *Config

NewConfig returns a new Config with default values

func (*Config) UnmarshalJSON added in v0.3.1

func (c *Config) UnmarshalJSON(data []byte) error

type Result

type Result struct {
	FilePath string
	FileName string
	Count    int64
}

Result is the result of a single file count it contains the file path and the number of lines

type Runner

type Runner struct {

	// the Directory to be processed
	Directory string

	// specifies whether to count files, lines or characters
	Action measureAction

	// Configurations that determine how the command count process should be performed
	*Config
	// contains filtered or unexported fields
}

Runner is the main struct that processes the files in a folder

func (*Runner) Run

func (r *Runner) Run() ([]*Result, error)

Run reads the files, coordinates the workers and returns the result array / errors if any this function is safe i.e. it doesn't throw when an error occurs so that the program can report all errors at once to the user.

Jump to

Keyboard shortcuts

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