可以轻松地从 Go 程序或 Markdown 无序列表中输出 ASCII 树。还有一个 CLI 工具,可以从 JSON、YAML 或 TOML 中输出树!它叫做 *xtree*。
可以轻松地从 Go 程序或 Markdown 无序列表中输出 ASCII 树。还有一个 CLI 工具,可以从 JSON、YAML 或 TOML 中输出树!它叫做 *xtree*。
Easily output ASCII tree from Go program or Markdown unordered list (and it does more than just output tree!)
There's also a CLI tool that can output a tree from JSON, YAML, or TOML! It's called xtree.
[!NOTE] There are sample repositories that use gtree package.
See here for details.
I urge you to run this program. This package is probably the easiest Go package to output tree.
…Go version requires 1.24 or later.
$ go get github.com/ddddddO/gtree| Function | Description | Available optional functions |
|---|---|---|
| OutputFromRoot | can output tree | WithMidBranch |
| WithLastBranch | ||
| WithVLine | ||
| WithHLine | ||
| WithEncodeJSON | ||
| WithEncodeTOML | ||
| WithEncodeYAML | ||
| MkdirFromRoot | can create directories | WithTargetDir |
| WithFileExtensions | ||
| WithDryRun | ||
| VerifyFromRoot | can output the difference between tree you composed and directories | WithTargetDir |
| WithStrictVerify | ||
| WalkFromRoot | can execute user-defined function while traversing tree structure recursively | WithMidBranch |
| WithLastBranch | ||
| WithVLine | ||
| WithHLine | ||
| WalkIterFromRoot | it returns each node resulting from a recursive traversal of the tree structure, so you can process on each node | WithMidBranch |
| WithLastBranch | ||
| WithVLine | ||
| WithHLine |
[!TIP] Specifying WithDuplicationAllowed function in NewRoot function, which generates the Node arguments for the above functions, allows multiple nodes with the same text to exist within the same hierarchy.
…Everyone is encouraged to use them!
CLI for Amazon S3 tree output.
aws s3 command does not do what tree command does, but stree command can display tree!
CLI for Google Cloud Storage tree output.
gcloud storage command does not do what tree command does, but gcstree command can display tree!
I hope you will use these tools as well!
Go version requires 1.24 or later.
$ go get github.com/ddddddO/gtreeThe symbols that can be used in Markdown are *, -, +, and #.
| Function | Description | Available optional functions |
|---|---|---|
| OutputFromMarkdown | can output trees | WithMidBranch |
| WithLastBranch | ||
| WithVLine | ||
| WithHLine | ||
| WithEncodeJSON | ||
| WithEncodeTOML | ||
| WithEncodeYAML | ||
| WithMassive | ||
| MkdirFromMarkdown | can create directories | WithTargetDir |
| WithFileExtensions | ||
| WithDryRun | ||
| WithMassive | ||
| VerifyFromMarkdown | can output the difference between markdown and directories | WithTargetDir |
| WithStrictVerify | ||
| WithMassive | ||
| WalkFromMarkdown | can execute user-defined function while traversing tree structure recursively | WithMidBranch |
| WithLastBranch | ||
| WithVLine | ||
| WithHLine | ||
| WithMassive |
https://ddddddo.github.io/gtree/
This page is that converts from Markdown to tree!
This page calls a function that outputs tree. This function is a Go package compiled as WebAssembly.
The symbols that can be used in Markdown are *, -, +, and #.
Indentation represents hierarchy. The indentation can be whatever you specify, but use the same pattern.
You can change the branches like in the image below.
Also, once loaded, you can enjoy offline!
You can open it in your browser with
$ gtree webGo $ go install github.com/ddddddO/gtree/cmd/gtree@latest
aqua $ aqua g -i ddddddO/gtree
Homebrew $ brew install gtree
Nix $ nix-env -i gtree or $ nix-shell -p gtree
MacPorts $ port install gtree
AUR $ wip...
Scoop $ scoop bucket add ddddddO https://github.com/ddddddO/scoop-bucket.git $ scoop install ddddddO/gtree
deb $ export GTREE_VERSION=X.X.X $ curl -o gtree.deb -L https://github.com/ddddddO/gtree/releases/download/v$GTREE_VERSION/gtree_$GTREE_VERSION-1_amd64.deb $ dpkg -i gtree.deb
rpm $ export GTREE_VERSION=X.X.X $ yum install https://github.com/ddddddO/gtree/releases/download/v$GTREE_VERSION/gtree_$GTREE_VERSION-1_amd64.rpm
apk $ export GTREE_VERSION=X.X.X $ curl -o gtree.apk -L https://github.com/ddddddO/gtree/releases/download/v$GTREE_VERSION/gtree_$GTREE_VERSION-1_amd64.apk $ apk add --allow-untrusted gtree.apk
Docker $ 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
download binary from here.
……$ 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.goOther pattern.
├── gtree output -f testdata/sample1.md
├── cat testdata/sample1.md | gtree output -f -
└── cat testdata/sample1.md | gtree output$ 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)
└── StatefulSet
└── Pod
└── container(s)$ cat testdata/sample6.md | gtree output
Artiodactyla
├── Artiofabula
│ ├── Cetruminantia
│ │ ├── Whippomorpha
│ │ │ ├── Hippopotamidae
│ │ │ └── Cetacea
│ │ └── Ruminantia
│ └── Suina
└── Tylopoda
Carnivora
├── Feliformia
└── Caniformia
├── Canidae
└── Arctoidea
├── Ursidae
└── x
├── Pinnipedia
└── Musteloidea
├── Ailuridae
└── x
├── Mephitidae
└── x
├── Procyonidae
└── Mustelidaesee
…see
$ cat testdata/sample5.md | gtree output --format yaml
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: []see
$ cat testdata/sample5.md | gtree output --format toml
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 = []
…$ 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$ 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 filesDoes 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 filesAny invalid file or directory name will result in an error.
$ gtree mkdir --dry-run
├── name
│ └── Alice
├── roles
│ ├── [0]
│ │ └── admin
│ └── [1]
│ └── editor
└── settings
├── notifications
│ └── true
└── theme
└── dark……$ cat a.json | xtree output --omit-index
.
├── age
│ └── 30
├── devices
│ ├── os
│ │ ├── ios
│ │ └── windows
│ └── type
│ ├── mobile
│ └── desktop
├── height
│ └── 175.5
├── is_active
│ └── true
├── metadata
│ └──
├── name
│ └── Alice
├── roles
│ ├── admin
│ └── editor
└── settings
├── notifications
│ └── true
└── theme
└── dark$ cat a.json | xtree output --level 1
.
├── age
├── devices
├── height
├── is_active
├── metadata
├── name
├── roles
└── settings
$ cat a.json | xtree output --level 2 --omit-index
.
├── age
│ └── 30
├── devices
│ ├── os
│ └── type
├── height
│ └── 175.5
├── is_active
│ └── true
├── metadata
│ └──
├── name
│ └── Alice
├── roles
│暂无开放 Issues,或尚未同步最近议题。