go-tree

module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2025 License: MIT

README

codecov CI Go Report Card Go Reference Go Version

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

Go-Tree

Documentation: bitspark.dev/go-tree

Features

  • Parse Go packages from directories
  • Extract package metadata (functions, types, constants, variables)
  • Format Go packages into a single source file
  • Generate JSON representation for use with static site generators
  • Configurable parsing and formatting options

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
CLI Options
  • -src: Source directory containing Go package (default: current directory)
  • -out-file: Output file for a single result (default: stdout)
  • -out-dir: Output directory where files are created with auto-generated names
  • -json: Output as JSON instead of formatted Go code
  • -batch: Comma-separated list of directories to process in batch mode
  • -include-tests: Include test files in parsing
  • -preserve-formatting: Preserve original formatting style
  • -skip-comments: Skip comments during parsing
  • -package: Custom package name for output

License

MIT

Directories

Path Synopsis
cmd
gotree
Command golm provides a CLI for parsing Go packages and formatting them into a single Go file
Command golm provides a CLI for parsing Go packages and formatting them into a single Go file
examples
basic
Example usage of the go-tree package
Example usage of the go-tree package
internal
formatter
Package formatter provides functionality for formatting Go packages
Package formatter provides functionality for formatting Go packages
model
Package model defines the core structures used for representing Go packages
Package model defines the core structures used for representing Go packages
parser
Package parser provides functionality for parsing Go packages into model structures
Package parser provides functionality for parsing Go packages into model structures
Package tree provides utilities for parsing and formatting Go packages.
Package tree provides utilities for parsing and formatting Go packages.

Jump to

Keyboard shortcuts

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