From 146d02e09e1e1093c14d8f57f79b6163bbb5f626 Mon Sep 17 00:00:00 2001 From: ddddddO Date: Sat, 10 Jun 2023 19:28:09 +0900 Subject: [PATCH] gtree description --- README.md | 13 ++----------- cmd/gtree/main.go | 29 ++++++++++++++++++++++++++--- testdata/sample0.md | 9 --------- 3 files changed, 28 insertions(+), 23 deletions(-) delete mode 100644 testdata/sample0.md diff --git a/README.md b/README.md index e540928..a2f261d 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ Output tree🌳 or Make directories📁 from Markdown or Programmatically.
Provide CLI, Go library and Web. -``` +```console +$ gtree template --description | gtree output # Description ├── Output tree from markdown or programmatically. │ ├── Output format is tree|yaml|toml|json. @@ -21,16 +22,6 @@ Provide CLI, Go library and Web. ``` -
-this description is output by - -```console -$ cat testdata/sample0.md | gtree output --fs -``` - -
- - ## Web
diff --git a/cmd/gtree/main.go b/cmd/gtree/main.go index e5b1a7b..f977010 100644 --- a/cmd/gtree/main.go +++ b/cmd/gtree/main.go @@ -86,6 +86,14 @@ func main() { }, } + templateFlags := []cli.Flag{ + &cli.BoolFlag{ + Name: "description", + Aliases: []string{"desc"}, + Usage: "Show gtree description.", + }, + } + app := &cli.App{ Name: "gtree", Usage: "This CLI outputs tree or makes directories from markdown.", @@ -110,9 +118,9 @@ func main() { Name: "template", Aliases: []string{"t", "tmpl"}, Usage: "Output markdown template.", - // Flags: NOTE: prepare various templates. - Before: notExistArgs, - Action: actionTemplate, + Flags: templateFlags, + Before: notExistArgs, + Action: actionTemplate, }, { Name: "version", @@ -259,7 +267,22 @@ const template = ` - tree.go ` +const description = "- # Description\n" + + " - Output tree from markdown or programmatically.\n" + + " - Output format is tree|yaml|toml|json.\n" + + " - Default tree.\n" + + " - Make directories from markdown or programmatically.\n" + + " - It is possible to dry run.\n" + + " - You can use `-e` flag to make specified extensions as file.\n" + + " - Output a markdown template that can be used with either `output` subcommand or `mkdir` subcommand.\n" + + " - Provide CLI, Go library and Web.\n" + func actionTemplate(c *cli.Context) error { + if c.Bool("description") { + fmt.Print(strings.TrimLeft(description, "\n")) + return nil + } + fmt.Print(strings.TrimLeft(template, "\n")) return nil } diff --git a/testdata/sample0.md b/testdata/sample0.md deleted file mode 100644 index b4f82fd..0000000 --- a/testdata/sample0.md +++ /dev/null @@ -1,9 +0,0 @@ -- # Description - - Output tree from markdown or programmatically. - - Output format is tree|yaml|toml|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 library and Web. \ No newline at end of file