countula

command
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT Imports: 14 Imported by: 0

README

Countula

countula is a command-line tool designed for counting lines of code (LOC) across various file types in a directory tree. It provides users with granular control to include or exclude specific files based on glob patterns and offers options to ignore lines with certain prefixes, such as comments.

Features

  • Flexible root directory specification.
  • Inclusion and exclusion of files through glob patterns.
  • Ignoring lines with specified prefixes.
  • Output can be directed to a file or stdout.
  • Option to group output by directory.
  • Merge mode for combined counts instead of per-extension details.

Installation

Currently, countula needs to be built from source:

# clone the repo
git clone https://github.com/toolvox/utilgo.git
# navigate to new .../utilgo directory
cd ./toolvox/utilgo
# go install
go install ./cmd/countula

Ensure you have Go installed on your system.

Usage

Below are some examples of how to use countula.

Basic Usage

To count all lines of code starting from the current directory and output to stdout:

$ countula
Specifying Root Directory

To specify a root directory other than the current directory:

$ countula -root "./my_project"
Including and Excluding Files

To include only .go, .json, and .md files, and exclude any files in a .git directory:

$ countula -include "*.go,*.json,*.md" -exclude ".git/*"
Ignoring Lines

To ignore lines that start with // or # (common comment patterns in many languages):

$ countula -ignore-prefix "//,#"
Output to a File

To write the output to a file named loc_report.txt:

$ countula -out "loc_report.txt"
Directory and Merge Modes

To group counts by directory and not split counts by file extension:

$ countula -dir-mode -merge-mode

Example Output

When running with -dir-mode and without -merge-mode:

Directory `src`:
    `.go`: 1200
    `.js`: 300

Directory `tests`:
    `.go`: 400

  ===  
Total lines: 1900

With -merge-mode enabled, the output might look like this:

Total lines: 1900

Or, with -dir-mode and -merge-mode:

Directory `src`:
    lines: 1500

Directory `tests`:
    lines: 400

  ===  
Total lines: 1900

Without any modes enabled, showing counts by extension globally:

Counts by extension:
    `.go`: 1600
    `.js`: 300

  ===  
Total lines: 1900

Reporting Issues

For any issues or feature requests, please open an issue on the GitHub repository.

License

countula is released under the MIT License. See the LICENSE file for more details.

Documentation

Overview

'countula' is a command-line tool designed to count lines of code in files across a directory tree, allowing for granular control over which files are included or excluded from the count.

Flags:

-root:          Sets the root directory from which to start traversal.
                If not specified, 'countula' defaults to the current working directory.

-include:       Specifies a comma-separated list of glob patterns to include in the traversal.
                Only files matching at least one of these patterns are considered for counting.
                If no includes are provided, everything except explicitly excluded patterns is included.

-exclude:       Specifies a comma-separated list of glob patterns to exclude from the traversal.
                Any file matching at least one of these patterns is ignored.

-out:           Determines the destination for the output report.
                Users can specify a file path to direct the output to a file, or leave this flag unspecified to default the output to standard output.

-ignore-prefix: Specifies line prefixes that trigger skipping the line, useful for ignoring comments or specific code patterns.

-dir-mode:      When set, the output groups counts by directory.

-merge-mode:    When set, the output does not split counts by file extension, merging them into a single count per directory or globally.

Example Usage:

$ countula -root "./source" -out "count_report.txt" -include "*.go,*.json,*.md" -exclude ".git" -ignore-prefix "//,#" -dir-mode

Jump to

Keyboard shortcuts

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