Skip to content

Library and command-line tool for parsing and formatting Go packages.

License

Notifications You must be signed in to change notification settings

Bitspark/go-tree

Repository files navigation

CI codecov Go Report Card Go Version Go Reference GitHub release (latest by date) License: MIT

Go-Tree

Library and command-line tool for analyzing and modifying Go code.

Documentation: bitspark.dev/go-tree

Features

  • Parse and format Go from source files
  • Extract structured package data (functions, types, constants, variables)
  • Generate JSON representations fully capturing the codebase
  • Configurable and available as CLI and Go library

Installation

# Install the library
go get bitspark.dev/go-tree

# Install the CLI tool
go install bitspark.dev/go-tree/cmd/gotree@latest

Library Usage

package main

import (
	"fmt"
	"bitspark.dev/go-tree/tree"
)

func main() {
	// Parse a Go package
	pkg, err := tree.Parse("./path/to/package")
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	
	// Get package info
	fmt.Printf("Package: %s\n", pkg.Name())
	fmt.Printf("Functions: %v\n", pkg.FunctionNames())
	fmt.Printf("Types: %v\n", pkg.TypeNames())
	
	// Format package to a single file
	output, err := pkg.Format()
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	
	fmt.Println(output)
}

CLI Usage

# Parse a package and output to stdout
gotree -src ./path/to/package

# Parse and save to file with options
gotree -src ./path/to/package -out-file output.go -include-tests -preserve-formatting

# Generate JSON documentation
gotree -src ./path/to/package -json -out-dir ./docs/json

# Process multiple packages in batch mode
gotree -batch "/path/to/pkg1,/path/to/pkg2" -json -out-dir ./docs/json

License

MIT