Skip to content

mayur57/treegen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

treegen

A command-line tool that generates directory structures and files from ASCII tree specifications.

Overview

treegen takes a text file containing an ASCII tree representation and creates the corresponding directory structure and files on your filesystem. It's useful for quickly setting up project templates, scaffolding applications, or creating test directory structures.

Features

  • ASCII Tree Parsing: Supports various tree connector symbols (├──, └──, , |--, \--, etc.)
  • Flexible Indentation: Configurable indent width (default: 4 spaces)
  • Dry Run Mode: Preview what would be created without actually creating files
  • Automatic Directory Inference: Automatically detects directories based on tree structure
  • Cross-Platform: Works on Windows, macOS, and Linux

Installation

Prerequisites

  • Go 1.16 or later

Build from Source

git clone <repository-url>
cd treegen
go build -o treegen main.go

Usage

./treegen [-width N] [-dry] <spec-file>

Options

  • -width N: Set the number of spaces per indent level (default: 4)
  • -dry: Dry run mode - show what would be created without creating files
  • <spec-file>: Path to the specification file containing the ASCII tree

Examples

Basic Usage

Create a spec file project.spec:

my-project/
├── src/
│   ├── main.go
│   └── utils.go
├── docs/
│   └── README.md
├── tests/
│   └── test.go
└── Makefile

Run TreeGen:

./treegen project.spec

This will create:

my-project/
├── src/
│   ├── main.go
│   └── utils.go
├── docs/
│   └── README.md
├── tests/
│   └── test.go
└── Makefile

Dry Run Mode

Preview what would be created:

./treegen -dry project.spec

Output:

[dry] mkdir -p my-project
[dry] mkdir -p my-project/src
[dry] touch my-project/src/main.go
[dry] touch my-project/src/utils.go
[dry] mkdir -p my-project/docs
[dry] touch my-project/docs/README.md
[dry] mkdir -p my-project/tests
[dry] touch my-project/tests/test.go
[dry] touch my-project/Makefile

Custom Indent Width

For spec files with different indentation:

./treegen -width 2 project.spec

Simple File Structure

You can also specify simple file paths:

a/b/c/d/e.txt

This creates the directory structure a/b/c/d/ and the file e.txt inside it.

Specification Format

treegen supports various ASCII tree formats:

Standard Tree Symbols

project/
├── src/
│   ├── main.go
│   └── utils.go
└── docs/
    └── README.md

Alternative Symbols

project/
|-- src/
|   |-- main.go
|   \-- utils.go
\-- docs/
    \-- README.md

Mixed Symbols

project/
├── src/
│   ├── main.go
│   └── utils.go
└── docs/
    └── README.md

Directory Detection

Directories are automatically detected in two ways:

  1. Explicit: Names ending with / are treated as directories
  2. Implicit: Items that have children (nodes with greater depth) are treated as directories

Supported Tree Symbols

TreeGen recognizes these connector symbols:

  • ├── (branch with continuation)
  • └── (branch end)
  • (vertical line)
  • |-- (alternative branch)
  • \-- (alternative branch end)
  • ├─ (short branch)
  • └─ (short branch end)
  • And various Unicode alternatives

Error Handling

  • File Already Exists: TreeGen will skip existing files and report them
  • Permission Errors: Clear error messages for permission issues
  • Invalid Spec Files: Graceful handling of malformed input

Use Cases

  • Project Scaffolding: Quickly set up new project structures
  • Testing: Create test directory structures for unit tests
  • Documentation: Generate example directory layouts
  • Templates: Create reusable project templates
  • Development: Set up development environments quickly

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

Examples

Web Application Structure

webapp/
├── public/
│   ├── index.html
│   ├── css/
│   │   └── style.css
│   └── js/
│       └── app.js
├── src/
│   ├── components/
│   │   ├── Header.js
│   │   └── Footer.js
│   └── utils/
│       └── helpers.js
├── tests/
│   └── app.test.js
├── package.json
└── README.md

Go Project Structure

myapp/
├── cmd/
│   └── myapp/
│       └── main.go
├── internal/
│   ├── handler/
│   │   └── handler.go
│   └── service/
│       └── service.go
├── pkg/
│   └── utils/
│       └── utils.go
├── go.mod
└── README.md

About

CLI tool that generates directory structures and files from ASCII tree specifications

Topics

Resources

Stars

Watchers

Forks

Languages