tree-create

Crates.iotree-create
lib.rstree-create
version0.3.0
sourcesrc
created_at2024-10-20 01:04:42.141846
updated_at2024-10-29 00:44:13.535872
descriptionA utility to create directory structures from a tree-like text input
homepage
repositoryhttps://github.com/codyw912/tree-create
max_upload_size
id1415839
size42,212
(codyw912)

documentation

README

tree-create

A command-line utility to create directory structures from tree-like text input.

Installation

cargo install tree-create

Usage

tree-create supports multiple ways to input your directory structure:

Interactive Editor (Default)

Simply run tree-create with no arguments to open your default editor:

tree-create

This will open your system's default editor (defined by $EDITOR) where you can input your directory structure. Save and close the file when you're done, and it will create the structure.

File Input

Pass a file containing your directory structure:

tree-create input.txt

Inline Input

Use the -i or --inline flag to input the structure directly in the terminal:

tree-create -i

Input Formats

tree-create supports two input formats:

ASCII Tree Format

my-project/
├── src/
│   ├── main.rs
│   └── lib.rs
└── Cargo.toml

Simple Indented Format

You can use any consistent indentation (spaces or tabs):

my-project/
  src/
    main.rs
    lib.rs
  Cargo.toml

or

my-project/
    src/
        main.rs
        lib.rs
    Cargo.toml

Rules and Validation

  • Root directory must not be indented
  • Indentation must be consistent throughout the structure
  • Can't skip indentation levels
  • Directories must end with a forward slash (/)
  • Empty lines are ignored

Examples

Create a simple Rust project structure:

my-project/
  src/
    main.rs
    lib.rs
  Cargo.toml

Create a more complex web project:

web-app/
  src/
    components/
      ui/
        buttons/
          primary.rs
          secondary.rs
        inputs/
          text.rs
          number.rs
    pages/
      home.rs
      about.rs
  public/
    index.html
    styles.css
  Cargo.toml

Handling Existing Files and Directories

By default, tree-create will:

  • Skip creating directories and files that already exist (preserving their contents)
  • Create any new directories and files in the structure
  • Print messages indicating which items were skipped and which were created

To overwrite existing files and directories, use the --force flag:

tree-create --force input.txt

When using --force:

  • Existing files will be overwritten (emptied)
  • Existing directories will be preserved, but any files specified in the tree will be overwritten
  • If a file exists where a directory is specified (or vice versa), it will be replaced

Note: Be careful with --force as it will overwrite files without confirmation.

Supported Editors

The following editors are explicitly supported for interactive mode:

  • vim/neovim
  • nano
  • VS Code (automatically adds --wait flag)

Other editors may work but are not officially supported.

Commit count: 12

cargo fmt