Skip to content

Commit 9dd4fe3

Browse files
committed
- [*] regulate main dispatcher name too
1 parent 6faa4b1 commit 9dd4fe3

4 files changed

Lines changed: 35 additions & 30 deletions

File tree

cli-ext.tmpl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var root = &cli.Command{
3636
{{if .Global}} Global: {{.Global}},
3737
{{end}}{{if .Self}} Argv: func() interface{} { t := new(rootT); t.Self = t; return t },
3838
{{else}} Argv: func() interface{} { return new(rootT) },
39-
{{end}} Fn: {{.Name}},
39+
{{end}} Fn: {{clk2uc .Name}},
4040
{{if .NumOption}}
4141
NumOption: {{.NumOption}},
4242
{{end}}{{if .NumArg}}
@@ -74,9 +74,7 @@ var root = &cli.Command{
7474

7575
// Function main
7676
// func main() {
77-
// cli.SetUsageStyle({{or .Style "cli.DenseNormalStyle"}}) // left-right, for up-down, use ManualStyle
78-
// //NOTE: You can set any writer implements io.Writer
79-
// // default writer is os.Stdout
77+
// cli.SetUsageStyle({{or .Style "cli.DenseNormalStyle"}})
8078
// if err := cli.Root(root,{{range $i, $cmd := .Command}}
8179
// cli.Tree({{$cmd.Name}}Def){{if lt $i ($.Command | len | minus1)}},{{end}}{{end}}).Run(os.Args[1:]); err != nil {
8280
// fmt.Fprintln(os.Stderr, err)
@@ -89,7 +87,8 @@ var root = &cli.Command{
8987
//==========================================================================
9088
// Dumb root handler
9189

92-
// func {{.Name}}(ctx *cli.Context) error {
90+
// {{clk2uc .Name}} - main dispatcher dumb handler
91+
// func {{clk2uc .Name}}(ctx *cli.Context) error {
9392
// ctx.JSON(ctx.RootArgv())
9493
// ctx.JSON(ctx.Argv())
9594
// fmt.Println()
@@ -116,11 +115,11 @@ var root = &cli.Command{
116115
//
117116
// Do{{stringsTitle .Name}} implements the business logic of command `{{.Name}}`
118117
// func Do{{stringsTitle .Name}}() error {
119-
// fmt.Fprintf(os.Stderr,
120-
// "%s v%s {{.Name}} - {{.Desc}}\n",
121-
// progname, version)
118+
// fmt.Fprintf(os.Stderr, "{{.Desc}}\n")
122119
// // fmt.Fprintf(os.Stderr, "Copyright (C) {{ date "Y4" }}, {{or $.Authors "The Author(s) <they@their.org>"}}\n\n")
123120
// // err := ...
121+
// // clis.WarnOn("Doing {{stringsTitle .Name}}", err)
122+
// // or,
124123
// // clis.AbortOn("Doing {{stringsTitle .Name}}", err)
125124
// return nil
126125
// }

cli-std.tmpl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var root = &cli.Command{
3434
{{if .Global}} Global: {{.Global}},
3535
{{end}}{{if .Self}} Argv: func() interface{} { t := new(rootT); t.Self = t; return t },
3636
{{else}} Argv: func() interface{} { return new(rootT) },
37-
{{end}} Fn: {{.Name}},
37+
{{end}} Fn: {{clk2uc .Name}},
3838
{{if .NumOption}}
3939
NumOption: {{.NumOption}},
4040
{{end}}{{if .NumArg}}
@@ -72,9 +72,7 @@ var root = &cli.Command{
7272

7373
// Function main
7474
// func main() {
75-
// cli.SetUsageStyle({{or .Style "cli.DenseNormalStyle"}}) // left-right, for up-down, use ManualStyle
76-
// //NOTE: You can set any writer implements io.Writer
77-
// // default writer is os.Stdout
75+
// cli.SetUsageStyle({{or .Style "cli.DenseNormalStyle"}})
7876
// if err := cli.Root(root,{{range $i, $cmd := .Command}}
7977
// cli.Tree({{$cmd.Name}}Def){{if lt $i ($.Command | len | minus1)}},{{end}}{{end}}).Run(os.Args[1:]); err != nil {
8078
// fmt.Fprintln(os.Stderr, err)
@@ -87,7 +85,8 @@ var root = &cli.Command{
8785
//==========================================================================
8886
// Dumb root handler
8987

90-
// func {{.Name}}(ctx *cli.Context) error {
88+
// {{clk2uc .Name}} - main dispatcher dumb handler
89+
// func {{clk2uc .Name}}(ctx *cli.Context) error {
9190
// ctx.JSON(ctx.RootArgv())
9291
// ctx.JSON(ctx.Argv())
9392
// fmt.Println()
@@ -114,11 +113,11 @@ var root = &cli.Command{
114113
//
115114
// Do{{stringsTitle .Name}} implements the business logic of command `{{.Name}}`
116115
// func Do{{stringsTitle .Name}}() error {
117-
// fmt.Fprintf(os.Stderr,
118-
// "%s v%s {{.Name}} - {{.Desc}}\n",
119-
// progname, version)
116+
// fmt.Fprintf(os.Stderr, "{{.Desc}}\n")
120117
// // fmt.Fprintf(os.Stderr, "Copyright (C) {{ date "Y4" }}, {{or $.Authors "The Author(s) <they@their.org>"}}\n\n")
121118
// // err := ...
119+
// // clis.WarnOn("Doing {{stringsTitle .Name}}", err)
120+
// // or,
122121
// // clis.AbortOn("Doing {{stringsTitle .Name}}", err)
123122
// return nil
124123
// }

wireframe_cliDef.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
////////////////////////////////////////////////////////////////////////////
22
// Program: wireframe
33
// Purpose: wire framing
4-
// Authors: Myself <me@mine.org> (c) 2019, All rights reserved
4+
// Authors: Myself <me@mine.org> (c) 2021, All rights reserved
55
////////////////////////////////////////////////////////////////////////////
66

77
package main
@@ -34,11 +34,11 @@ type rootT struct {
3434
var root = &cli.Command{
3535
Name: "wireframe",
3636
Desc: "wire framing\nVersion " + version + " built on " + date +
37-
"\nCopyright (C) 2019, Myself <me@mine.org>",
37+
"\nCopyright (C) 2021, Myself <me@mine.org>",
3838
Text: "Tool to showcase wire-framing command line app fast prototype",
3939
Global: true,
4040
Argv: func() interface{} { t := new(rootT); t.Self = t; return t },
41-
Fn: wireframe,
41+
Fn: Wireframe,
4242

4343
NumArg: cli.AtLeast(1),
4444
}
@@ -64,7 +64,7 @@ var root = &cli.Command{
6464
// var (
6565
// progname = "wireframe"
6666
// version = "0.1.0"
67-
// date = "2019-09-12"
67+
// date = "2021-02-14"
6868

6969
// rootArgv *rootT
7070
// // Opts store all the configurable options
@@ -76,9 +76,7 @@ var root = &cli.Command{
7676

7777
// Function main
7878
// func main() {
79-
// cli.SetUsageStyle(cli.DenseNormalStyle) // left-right, for up-down, use ManualStyle
80-
// //NOTE: You can set any writer implements io.Writer
81-
// // default writer is os.Stdout
79+
// cli.SetUsageStyle(cli.DenseNormalStyle)
8280
// if err := cli.Root(root,
8381
// cli.Tree(putDef),
8482
// cli.Tree(getDef)).Run(os.Args[1:]); err != nil {
@@ -92,7 +90,8 @@ var root = &cli.Command{
9290
//==========================================================================
9391
// Dumb root handler
9492

95-
// func wireframe(ctx *cli.Context) error {
93+
// Wireframe - main dispatcher dumb handler
94+
// func Wireframe(ctx *cli.Context) error {
9695
// ctx.JSON(ctx.RootArgv())
9796
// ctx.JSON(ctx.Argv())
9897
// fmt.Println()
@@ -119,8 +118,12 @@ var root = &cli.Command{
119118
//
120119
// DoPut implements the business logic of command `put`
121120
// func DoPut() error {
122-
// fmt.Fprintf(os.Stderr, "%s v%s. put - Upload into service\n", progname, version)
123-
// // fmt.Fprintf(os.Stderr, "Copyright (C) 2019, Myself <me@mine.org>\n\n")
121+
// fmt.Fprintf(os.Stderr, "Upload into service\n")
122+
// // fmt.Fprintf(os.Stderr, "Copyright (C) 2021, Myself <me@mine.org>\n\n")
123+
// // err := ...
124+
// // clis.WarnOn("Doing Put", err)
125+
// // or,
126+
// // clis.AbortOn("Doing Put", err)
124127
// return nil
125128
// }
126129

@@ -155,8 +158,12 @@ var putDef = &cli.Command{
155158
//
156159
// DoGet implements the business logic of command `get`
157160
// func DoGet() error {
158-
// fmt.Fprintf(os.Stderr, "%s v%s. get - Get from the service\n", progname, version)
159-
// // fmt.Fprintf(os.Stderr, "Copyright (C) 2019, Myself <me@mine.org>\n\n")
161+
// fmt.Fprintf(os.Stderr, "Get from the service\n")
162+
// // fmt.Fprintf(os.Stderr, "Copyright (C) 2021, Myself <me@mine.org>\n\n")
163+
// // err := ...
164+
// // clis.WarnOn("Doing Get", err)
165+
// // or,
166+
// // clis.AbortOn("Doing Get", err)
160167
// return nil
161168
// }
162169

wireframe_main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"os"
1414
"strings"
1515

16-
"github.com/mkideal/cli"
1716
"github.com/labstack/gommon/color"
17+
"github.com/mkideal/cli"
1818
)
1919

2020
////////////////////////////////////////////////////////////////////////////
@@ -62,7 +62,7 @@ func main() {
6262
//==========================================================================
6363
// Main dispatcher
6464

65-
func wireframe(ctx *cli.Context) error {
65+
func Wireframe(ctx *cli.Context) error {
6666
ctx.JSON(ctx.RootArgv())
6767
ctx.JSON(ctx.Argv())
6868
fmt.Println()

0 commit comments

Comments
 (0)