Untree converts tree diagrams produced by tree back into directory file structures.

Overview

Untree: Undoing tree for fun and profit

Untree converts tree diagrams produced by tree back into directory file structures.

Let's say you have the following directory structure, created by running tree in the root of this project:

.
├── Cargo.lock
├── Cargo.toml
├── inputs
│   └── test1.tree
├── README.md
└── src
    ├── macros.rs
    ├── main.rs
    ├── traits.rs
    └── types.rs

2 directories, 8 files

untree can mirror that directory structure, just based on that input:

tree | untree --dir test

Here, test is the destination directory where untree is supposed to create files. Now, if we tree the newly created directory, we can see that it has the same structure as the repository:

test
├── Cargo.lock
├── Cargo.toml
├── inputs
│   └── test1.tree
├── README.md
└── src
    ├── macros.rs
    ├── main.rs
    ├── traits.rs
    └── types.rs

2 directories, 8 files

untree can also read in the tree from an input file, or you can paste it in directly since it accepts input from standard input:

Motivating untree

I've noticed that in the past I've had to recreate directory structures in order to answer questions or run tests on the directory. For example, this question asks about ignoring certain kinds of files, and it provides a directory structure as reference.

The files themselves aren't provided, nor do they need to be, but the directory structure itself is relevant to the question.

untree allows you to exactly replicate the directory structure, just by pasting in the given directory tree:

Aside from allowing you to answer questions about directory structures, untree is good for quickly creating directory structures for the purpose of mocking input to other programs.

Using untree as a library

You can use untree as a library if you need that functionality included in your program. In order to create a tree, invoke untree::create_tree with the given directory, Lines buffer, and options. These options are very simple - there's UntreeOptions::verbose, which will print out any directories or files that were created if true, and UntreeOptions::dry_run, which will print out any directories or files without actually creating them (dry_run implies verbose)

For more info, see the documentation.

pub fn create_tree(
    directory: &String,
    mut lines: Lines<impl BufRead>,
    options: UntreeOptions,
)

Additional functions, such as untree::create_path, untree::get_entry (used to parse a line in a tree file), untree::touch_directory (used to create a directory, returning an untree::Error on failure), and untree::file (used to touch a file, returning untree::Error on failure) are also provided.

The primary error type used by untree is untree::Error, which holds information about a path and the action being done on it, in addition to the normal error information provided by io::Error.

User testimonials

When asked about untree, my friend said:

I retroactively want that for my time trying to get Conan to work. It woulda made certain things just a little less painful.

some guy (He asked to be referred to as "some guy")

Comments, feedback, or contributions are welcome!

I'm in the progress of learning rust, so any feedback you have is greatly appreciated! Also, if untree is useful to you, please let me know!

You might also like...
A library for comparing data structures in Rust, oriented toward testing

The comparable crate defines the trait [Comparable], along with a derive macro for auto-generating instances of this trait for most data types. Primar

Collection of Data Structures in Rust

cds - Collection of Data Structures !!! UNDER CONSTRUCTION !!! The version v0.0.1 is a crates.io placeholder. License Licensed under either of Apache

Succinct data structures in Rust

sucds: Succinct data structures in Rust sucds contains some succinct data structures written in Rust. Data structures So far, the following data struc

Coding-challenge - Algorithms and Data-structures, problems and solutions in Rust language using cargo-workspaces

Coding Challenge LeetCode/Hackerrank e.t.c Using this as an opportunity to improve my knowledge of rust lang If you found this repo useful to you, add

Rust-algorithm-club - Learn algorithms and data structures with Rust

Rust Algorithm Club 🚧 🚧 This repo is under construction. Most materials are written in Chinese. Check it out here if you are able to read Chinese. W

Common data structures and algorithms in Rust

Contest Algorithms in Rust A collection of classic data structures and algorithms, emphasizing usability, beauty and clarity over full generality. As

Library containing implementations of various sequential data-structures.

Library containing implementations of various sequential data-structures.

Rust data structures and client for the PubChem REST API

pubchem.rs Rust data structures and client for the PubChem REST API. 🔌 Usage 💊 Compound Create a Compound to query the PubChem API for a single comp

Dade is data definition for Rust structures.

dade dade is data definition for Rust structures. For the easy handle of data, the following will support it. Data validation. Data schema conforms Js

Owner
Alecto Irene Perez
Undergrad at UNM; interested in Web Development, Modern C++, Haskell, and Machine Learning
Alecto Irene Perez
Broot - A new way to see and navigate directory trees

Broot A better way to navigate directories Installation Instructions Get an overview of a directory, even a big one br -s Notice the unlisted? That's

Canop 8k Jan 8, 2023
Rust Persistent Data Structures

Rust Persistent Data Structures Rust Persistent Data Structures provides fully persistent data structures with structural sharing. Setup To use rpds a

Diogo Sousa 883 Dec 31, 2022
A proof of concept implementation of cyclic data structures in stable, safe, Rust.

A proof of concept implementation of cyclic data structures in stable, safe, Rust. This demonstrates the combined power of the static-rc crate and the

null 157 Dec 28, 2022
Rust library for string parsing of basic data structures.

afmt Simple rust library for parsing basic data structures from strings. Usage You can specify string formats to any strucute, via the use of the fmt

Eduard 4 May 8, 2021
Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.

Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.

null 6.5k Dec 31, 2022
Algorithms and Data Structures of all kinds written in Rust.

Classic Algorithms in Rust This repo contains the implementation of various classic algorithms for educational purposes in Rust. Right now, it is in i

Alexander González 49 Dec 14, 2022
Obake is a procedural macro for declaring and maintaining versioned data-structures.

Obake is a procedural macro for declaring and maintaining versioned data-structures. The name 'obake' is taken from the Japanese 'お化け (おばけ)', a class of supernatural beings in Japanese folklore that shapeshift.

Nathan Corbyn 174 Dec 26, 2022
Garbage Collector(Hyaline- Safe Memory Reclaimation) for lock free data structures

Hyaline-SMR This crate provides garbage collection using hyaline algorithm for building concurrent data structures. When a thread removes an object fr

Abishek 2 Dec 21, 2022
Library containing various Data Structures implemented using Rust.

rust-data-structures Library containing various Data Structures implemented using Rust. Running You can test the library by running cargo test, an exa

c1m50c 1 Jan 6, 2022
A library for comparing data structures in Rust, oriented toward testing

Delta: Structural differencing in Rust The delta crate defines the trait Delta, along with a derive macro for auto-generating instances of this trait

John Wiegley 19 Oct 7, 2022