Skip to content

Commit

Permalink
ファイル生成機能とmarkdown template出力機能 (#29)
Browse files Browse the repository at this point in the history
* add Make file feature

* fix

* update readme

* refactor

* refactor

* refactor
  • Loading branch information
ddddddO authored Jan 15, 2022
1 parent 2b78751 commit 593ef2b
Show file tree
Hide file tree
Showing 13 changed files with 330 additions and 89 deletions.
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,42 @@

Output tree🌳 or Make directories📁 from Markdown or Programmatically. Provide CLI and Go Package.

⚠It is incompatible with v1.2.4 and earlier versions.
⚠It is incompatible with v1.2.4 and earlier versions⚠

```
## Description
# Description
├── Output tree from markdown or programmatically.
│ ├── Output format is stdout or yaml or toml or json.
│ └── Default stdout.
├── Make directories from markdown or programmatically.
│ └── It is possible to dry run.
│ ├── 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 and Go Package.
```
generated by `cat testdata/sample0.md | gtree output --fs`


## Summary Usage
```console
23:47:15 > 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 stdout or yaml or toml or json. Default stdout.
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)
```

---

## CLI
Expand Down
130 changes: 76 additions & 54 deletions README_CLI.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# CLI

## Installation

go version is 1.16 or higher
```console
go install github.com/ddddddO/gtree/cmd/gtree@latest
```

go version is 1.15 or less
```console
go get github.com/ddddddO/gtree/cmd/gtree
```

or, download from [here](https://github.com/ddddddO/gtree/releases).
or, download binary from [here](https://github.com/ddddddO/gtree/releases).

## Usage
### *Output*
Expand Down Expand Up @@ -259,70 +266,85 @@ children = []
### *Mkdir*

```console
23:02:39 > gtree mkdir --help
22:19:20 > gtree mkdir --help
NAME:
gtree mkdir - Make directories from markdown. It is possible to dry run.
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)
--help, -h show help (default: false)
--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)
```

```console
23:05:38 > cat testdata/sample2.md | gtree mkdir
23:08:08 > tree k8s_resources/
k8s_resources/
├── (Tier3)
│ └── (Tier2)
│ └── (Tier1)
│ └── (Tier0)
├── (empty)
│ ├── DaemonSet
│ │ └── Pod
│ │ └── container(s)
│ └── StatefulSet
│ └── Pod
│ └── container(s)
├── CronJob
│ └── Job
│ └── Pod
│ └── container(s)
└── Deployment
└── ReplicaSet
└── Pod
└── container(s)

19 directories, 0 files
22:25:18 > gtree template
- gtree
- cmd
- gtree
- main.go
- testdata
- sample1.md
- sample2.md
- makefile
- tree.go
22:26:06 > gtree template | gtree mkdir
22:26:14 > tree gtree/
gtree/
├── cmd
│ └── gtree
│ └── main.go
├── makefile
├── testdata
│ ├── sample1.md
│ └── sample2.md
└── tree.go

8 directories, 0 files
```

#### *dry run*
```console
23:04:13 > cat testdata/sample2.md | gtree mkdir --dry-run
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)
22:27:13 > gtree template | gtree mkdir --dry-run
gtree
├── cmd
│ └── gtree
│ └── main.go
├── testdata
│ ├── sample1.md
│ └── sample2.md
├── makefile
└── tree.go
```

#### *make directories and files*
```console
22:15:59 > gtree template
- gtree
- cmd
- gtree
- main.go
- testdata
- sample1.md
- sample2.md
- makefile
- tree.go
22:16:13 > gtree template | gtree mkdir -e .go -e .md -e makefile
22:16:19 > tree gtree/
gtree/
├── cmd
│ └── gtree
│ └── main.go
├── makefile
├── testdata
│ ├── sample1.md
│ └── sample2.md
└── tree.go

3 directories, 5 files
```
8 changes: 8 additions & 0 deletions README_Package_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go get github.com/ddddddO/gtree
```

## Usage
### *Output*

```go
package main
Expand Down Expand Up @@ -89,3 +90,10 @@ func main() {
- `gtree.WithEncodeJSON()`
- `gtree.WithEncodeTOML()`
- `gtree.WithEncodeYAML()`

---

### *Mkdir*

- `gtree.Mkdir` func makes directories.
- You can use `gtree.WithFileExtension` func to make specified extensions as file.
44 changes: 44 additions & 0 deletions README_Package_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,47 @@ func main() {
```

[details](https://github.com/ddddddO/gtree/blob/master/sample/programmable/main.go#L354)

---

- Make directories and files with specific extensions.

```go
package main

import (
"os"

"github.com/ddddddO/gtree"
)

func main() {
gtreeDir := gtree.NewRoot("gtree")
gtreeDir.Add("cmd").Add("main.go")
gtreeDir.Add("makefile")
testdataDir := gtreeDir.Add("testdata")
testdataDir.Add("sample1.md")
testdataDir.Add("sample2.md")
gtreeDir.Add("tree.go")

// make directories and files with specific extensions.
if err := gtree.MkdirProgrammably(
gtreeDir,
gtree.WithFileExtension([]string{".go", ".md", "makefile"}),
); err != nil {
panic(err)
}
// Output(using Linux 'tree' command):
// 21:57:09 > tree gtree/
// gtree/
// ├── cmd
// │ └── main.go
// ├── makefile
// ├── testdata
// │ ├── sample1.md
// │ └── sample2.md
// └── tree.go
//
// 2 directories, 5 files
}
```
Loading

0 comments on commit 593ef2b

Please sign in to comment.