Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Moderrek/lines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

18 Commits

Repository files navigation

A concurrent, non-blank line counter for source code directories, written in GO.

It recursively walks a directory, concurrently analyzes files, and reports the number of non-blank lines of code, grouped by file extension.

The tool is designed for performance, utilizing goroutines to process files in parallel.

Installation

To install the lines command-line tool, ensure you have Go installed and configured, then run:

go install github.com/moderrek/lines/cmd/lines@latest

This will download the source, compile it, and place the lines binary in your Go bin directory ($GOPATH/bin or $HOME/go/in).

Usage

The lines command accepts the following flags:

Usage: lines [options]
Options:
 -dir string
 The directory to analyze (default ".")
 -hidden
 Include hidden files and directories in the analysis
 -top uint
 Show only the top N extensions by line count
 -no-color
 Disable colorized output
 -json
 Output results in JSON format
 -version
 Print version information and exit
 -help
 Show this help message and exit

Example

To analyze the directory ~/projects/my-app and display the top 5 extensions:

lines --dir ~/projects/my-app --top 5

To get the output in JSON format, which can be piped to other tools like jq:

lines --dir ~/projects/my-app --json

Example output (--json):

{
 ".css": 1122,
 ".go": 15230,
 ".html": 4357,
 ".js": 8828,
 ".mod": 4980
}

Library Usage

The core counting logic is available as a library. It can be imported into other Go projects.

import "github.com/moderrek/lines/pkg/lines"

Example

package main
import (
	"fmt"
	"log"
	"github.com/moderrek/lines/pkg/lines"
)
func main() {
	// Configure the counter with default settings.
	config := lines.Config{
		IncludeHidden: false,
	}
	counter := lines.NewCounter(config)
	// Run the analysis on the current directory.
	result, err := counter.Run(".")
	if err != nil {
		log.Fatalf("Analysis failed: %v", err)
	}
	// Print results.
	for ext, count := range result.LinesByExtension {
		fmt.Printf("Extension: %s, Lines: %d\n", ext, count)
	}
}

Custom Configuration

You can customize which directories and file extensions to ignore:

config := lines.Config{
	IncludeHidden: false,
	IgnoredDirs: []string{"node_modules", "vendor", ".git", "target", "dist"},
	IgnoredExtensions: []string{".exe", ".dll", ".jpg", ".png"},
}
counter := lines.NewCounter(config)
result, err := counter.Run("./src")

If IgnoredDirs or IgnoredExtensions are not provided, the library uses sensible defaults.

Building from Source

  1. Clone the repository:
    git clone https://github.com/Moderrek/lines.git
  2. Navigate to the project directory:
    cd lines
  3. Build the binary:
    go build ./cmd/lines
    This will create a lines executable in the current directory.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Concurrent, non-blank line counter for source code directories.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /