gtree
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
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
Package(2) / generate a tree programmatically
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
- Markdownๅฝขๅผใฎๅ ฅๅใใtreeใๅบๅใใCLI
- Goใงtreeใ่กจ็พใใ
- Markdownๅฝขๅผใฎๅ ฅๅใใใใกใคใซ/ใใฃใฌใฏใใชใ็ๆใใCLI/Goใใใฑใผใธ
- ๆๆณ