gtree icon indicating copy to clipboard operation
gtree copied to clipboard

Using either Markdown or Programmatically to generate trees๐ŸŒณ and directories๐Ÿ“, and to verify directories๐Ÿ”. Provide CLI, Golang library and Web.

gtree

GitHub Pages
GitHub release Go Reference
License Mentioned in Awesome Go
ci codecov Go Report Card

Output tree๐ŸŒณ or Make directories(files)๐Ÿ“ from Markdown or Programmatically. Provide CLI, Go Packages and Web.

# Description
โ”œโ”€โ”€ Output tree from markdown or programmatically.
โ”‚   โ”œโ”€โ”€ Output format is tree or yaml or toml or json.
โ”‚   โ””โ”€โ”€ Default tree.
โ”œโ”€โ”€ Make directories from markdown or programmatically.
โ”‚   โ”œโ”€โ”€ It is possible to dry run.
โ”‚   โ””โ”€โ”€ You can use `-e` flag to make specified extensions as file.
โ”œโ”€โ”€ Output a markdown template that can be used with either `output` subcommand or `mkdir` subcommand.
โ””โ”€โ”€ Provide CLI, Go Packages and Web.

(outputted by cat testdata/sample0.md | gtree output --fs)

Web

https://ddddddo.github.io/gtree/

This page calls a function that outputs tree. This function is a Go package compiled as WebAssembly.
You can change the branches like in the image below.
Also, once loaded, you can enjoy offline!

Package(1) / like CLI

read me!

Package(2) / generate a tree programmatically

read me!

CLI

Installation

Go version requires 1.18 or later.

$ go install github.com/ddddddO/gtree/cmd/gtree@latest

or using Homebrew.

$ brew install ddddddO/tap/gtree

or docker image.

$ docker pull ghcr.io/ddddddo/gtree:latest
$ docker run ghcr.io/ddddddo/gtree:latest template | docker run -i ghcr.io/ddddddo/gtree:latest output
gtree
โ”œโ”€โ”€ cmd
โ”‚   โ””โ”€โ”€ gtree
โ”‚       โ””โ”€โ”€ main.go
โ”œโ”€โ”€ testdata
โ”‚   โ”œโ”€โ”€ sample1.md
โ”‚   โ””โ”€โ”€ sample2.md
โ”œโ”€โ”€ Makefile
โ””โ”€โ”€ tree.go

or, download binary from here.

Usage

$ gtree --help
NAME:
   gtree - This CLI outputs tree or makes directories from markdown.

USAGE:
   gtree [global options] command [command options] [arguments...]

COMMANDS:
   output, o, out     Output tree from markdown. Let's try 'gtree template | gtree output'. Output format is tree or yaml or toml or json. Default tree.
   mkdir, m           Make directories(and files) from markdown. It is possible to dry run. Let's try 'gtree template | gtree mkdir -e .go -e .md -e Makefile'.
   template, t, tmpl  Output markdown template.
   version, v         Output gtree version.
   help, h            Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h  show help (default: false)

Output subcommand

$ gtree output --help
NAME:
   gtree output - Output tree from markdown. Let's try 'gtree template | gtree output'. Output format is tree or yaml or toml or json. Default tree.

USAGE:
   gtree output [command options] [arguments...]

OPTIONS:
   --file value, -f value  Markdown file path. (default: stdin)
   --two-spaces, --ts      Markdown is Two Spaces indentation. (default: tab spaces)
   --four-spaces, --fs     Markdown is Four Spaces indentation. (default: tab spaces)
   --json, -j              Output JSON format. (default: stdout)
   --yaml, -y              Output YAML format. (default: stdout)
   --toml, -t              Output TOML format. (default: stdout)
   --watch, -w             Watching markdown file. (default: false)
   --help, -h              show help (default: false)
$ gtree template
- gtree
        - cmd
                - gtree
                        - main.go
        - testdata
                - sample1.md
                - sample2.md
        - Makefile
        - tree.go
$ gtree template | gtree output
gtree
โ”œโ”€โ”€ cmd
โ”‚   โ””โ”€โ”€ gtree
โ”‚       โ””โ”€โ”€ main.go
โ”œโ”€โ”€ testdata
โ”‚   โ”œโ”€โ”€ sample1.md
โ”‚   โ””โ”€โ”€ sample2.md
โ”œโ”€โ”€ Makefile
โ””โ”€โ”€ tree.go

When Markdown is indented as a tab.

โ”œโ”€โ”€ gtree output -f testdata/sample1.md
โ”œโ”€โ”€ cat testdata/sample1.md | gtree output -f -
โ””โ”€โ”€ cat testdata/sample1.md | gtree output

For 2 or 4 spaces instead of tabs, -ts or -fs is required.

More details
  • Usage other than representing a directory.
$ cat testdata/sample2.md | gtree output
k8s_resources
โ”œโ”€โ”€ (Tier3)
โ”‚   โ””โ”€โ”€ (Tier2)
โ”‚       โ””โ”€โ”€ (Tier1)
โ”‚           โ””โ”€โ”€ (Tier0)
โ”œโ”€โ”€ Deployment
โ”‚   โ””โ”€โ”€ ReplicaSet
โ”‚       โ””โ”€โ”€ Pod
โ”‚           โ””โ”€โ”€ container(s)
โ”œโ”€โ”€ CronJob
โ”‚   โ””โ”€โ”€ Job
โ”‚       โ””โ”€โ”€ Pod
โ”‚           โ””โ”€โ”€ container(s)
โ”œโ”€โ”€ (empty)
โ”‚   โ””โ”€โ”€ DaemonSet
โ”‚       โ””โ”€โ”€ Pod
โ”‚           โ””โ”€โ”€ container(s)
โ””โ”€โ”€ (empty)
    โ””โ”€โ”€ StatefulSet
        โ””โ”€โ”€ Pod
            โ””โ”€โ”€ container(s)

  • Two spaces indent
$ cat testdata/sample4.md | gtree output -ts
a
โ”œโ”€โ”€ i
โ”‚   โ”œโ”€โ”€ u
โ”‚   โ”‚   โ”œโ”€โ”€ k
โ”‚   โ”‚   โ””โ”€โ”€ kk
โ”‚   โ””โ”€โ”€ t
โ”œโ”€โ”€ e
โ”‚   โ””โ”€โ”€ o
โ””โ”€โ”€ g
  • Four spaces indent
$ cat testdata/sample5.md | gtree output -fs
a
โ”œโ”€โ”€ i
โ”‚   โ”œโ”€โ”€ u
โ”‚   โ”‚   โ”œโ”€โ”€ k
โ”‚   โ”‚   โ””โ”€โ”€ kk
โ”‚   โ””โ”€โ”€ t
โ”œโ”€โ”€ e
โ”‚   โ””โ”€โ”€ o
โ””โ”€โ”€ g
  • Multiple roots
$ cat testdata/sample6.md | gtree output
a
โ”œโ”€โ”€ i
โ”‚   โ”œโ”€โ”€ u
โ”‚   โ”‚   โ”œโ”€โ”€ k
โ”‚   โ”‚   โ””โ”€โ”€ kk
โ”‚   โ””โ”€โ”€ t
โ”œโ”€โ”€ e
โ”‚   โ””โ”€โ”€ o
โ””โ”€โ”€ g
a
โ”œโ”€โ”€ i
โ”‚   โ”œโ”€โ”€ u
โ”‚   โ”‚   โ”œโ”€โ”€ k
โ”‚   โ”‚   โ””โ”€โ”€ kk
โ”‚   โ””โ”€โ”€ t
โ”œโ”€โ”€ e
โ”‚   โ””โ”€โ”€ o
โ””โ”€โ”€ g
  • Output JSON
$ cat testdata/sample5.md | gtree output -fs -j | jq
{
  "value": "a",
  "children": [
    {
      "value": "i",
      "children": [
        {
          "value": "u",
          "children": [
            {
              "value": "k",
              "children": null
            },
            {
              "value": "kk",
              "children": null
            }
          ]
        },
        {
          "value": "t",
          "children": null
        }
      ]
    },
    {
      "value": "e",
      "children": [
        {
          "value": "o",
          "children": null
        }
      ]
    },
    {
      "value": "g",
      "children": null
    }
  ]
}
  • Output YAML
$ cat testdata/sample5.md | gtree output -fs -y
value: a
children:
- value: i
  children:
  - value: u
    children:
    - value: k
      children: []
    - value: kk
      children: []
  - value: t
    children: []
- value: e
  children:
  - value: o
    children: []
- value: g
  children: []
  • Output TOML
$ cat testdata/sample5.md | gtree output -fs -t
value = 'a'
[[children]]
value = 'i'
[[children.children]]
value = 'u'
[[children.children.children]]
value = 'k'
children = []
[[children.children.children]]
value = 'kk'
children = []

[[children.children]]
value = 't'
children = []

[[children]]
value = 'e'
[[children.children]]
value = 'o'
children = []

[[children]]
value = 'g'
children = []


Mkdir subcommand

$ gtree mkdir --help
NAME:
   gtree mkdir - Make directories from markdown. It is possible to dry run. Let's try 'gtree template | gtree mkdir -e .go -e .md -e Makefile'.

USAGE:
   gtree mkdir [command options] [arguments...]

OPTIONS:
   --file value, -f value                    Markdown file path. (default: stdin)
   --two-spaces, --ts                        Markdown is Two Spaces indentation. (default: tab spaces)
   --four-spaces, --fs                       Markdown is Four Spaces indentation. (default: tab spaces)
   --dry-run, -d, --dr                       Dry run. Detects node that is invalid for directory generation. The order of the output and made directories does not always match. (default: false)
   --extension value, -e value, --ext value  Specified extension will be created as file.
   --help, -h                                show help (default: false)
$ gtree template
- gtree
        - cmd
                - gtree
                        - main.go
        - testdata
                - sample1.md
                - sample2.md
        - Makefile
        - tree.go
$ gtree template | gtree mkdir
$ tree gtree/
gtree/
โ”œโ”€โ”€ cmd
โ”‚   โ””โ”€โ”€ gtree
โ”‚       โ””โ”€โ”€ main.go
โ”œโ”€โ”€ Makefile
โ”œโ”€โ”€ testdata
โ”‚   โ”œโ”€โ”€ sample1.md
โ”‚   โ””โ”€โ”€ sample2.md
โ””โ”€โ”€ tree.go

8 directories, 0 files
make directories and files
$ gtree template
- gtree
        - cmd
                - gtree
                        - main.go
        - testdata
                - sample1.md
                - sample2.md
        - Makefile
        - tree.go
$ gtree template | gtree mkdir -e .go -e .md -e Makefile
$ tree gtree/
gtree/
โ”œโ”€โ”€ cmd
โ”‚   โ””โ”€โ”€ gtree
โ”‚       โ””โ”€โ”€ main.go
โ”œโ”€โ”€ Makefile
โ”œโ”€โ”€ testdata
โ”‚   โ”œโ”€โ”€ sample1.md
โ”‚   โ””โ”€โ”€ sample2.md
โ””โ”€โ”€ tree.go

3 directories, 5 files
dry run

Does not create a file and directory.

$ gtree template | gtree mkdir --dry-run -e .go -e .md -e Makefile
gtree
โ”œโ”€โ”€ cmd
โ”‚   โ””โ”€โ”€ gtree
โ”‚       โ””โ”€โ”€ main.go
โ”œโ”€โ”€ testdata
โ”‚   โ”œโ”€โ”€ sample1.md
โ”‚   โ””โ”€โ”€ sample2.md
โ”œโ”€โ”€ Makefile
โ””โ”€โ”€ tree.go

4 directories, 5 files

โ†‘ colored output

Any invalid file or directory name will result in an error.

$ gtree mkdir --dry-run --ts <<EOS
- root
  - aa
  - bb
    - b/b
EOS
invalid node name: b/b
$ gtree mkdir --dry-run --ts <<EOS
- /root
  - aa
  - bb
    - bb
EOS
invalid path: /root/aa

Documents

Star History

Star History Chart