Skip to content

Commit

Permalink
- [*] regulate main dispatcher name too
Browse files Browse the repository at this point in the history
  • Loading branch information
suntong committed Feb 15, 2021
1 parent 6faa4b1 commit 9dd4fe3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 30 deletions.
15 changes: 7 additions & 8 deletions cli-ext.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var root = &cli.Command{
{{if .Global}} Global: {{.Global}},
{{end}}{{if .Self}} Argv: func() interface{} { t := new(rootT); t.Self = t; return t },
{{else}} Argv: func() interface{} { return new(rootT) },
{{end}} Fn: {{.Name}},
{{end}} Fn: {{clk2uc .Name}},
{{if .NumOption}}
NumOption: {{.NumOption}},
{{end}}{{if .NumArg}}
Expand Down Expand Up @@ -74,9 +74,7 @@ var root = &cli.Command{

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

// func {{.Name}}(ctx *cli.Context) error {
// {{clk2uc .Name}} - main dispatcher dumb handler
// func {{clk2uc .Name}}(ctx *cli.Context) error {
// ctx.JSON(ctx.RootArgv())
// ctx.JSON(ctx.Argv())
// fmt.Println()
Expand All @@ -116,11 +115,11 @@ var root = &cli.Command{
//
// Do{{stringsTitle .Name}} implements the business logic of command `{{.Name}}`
// func Do{{stringsTitle .Name}}() error {
// fmt.Fprintf(os.Stderr,
// "%s v%s {{.Name}} - {{.Desc}}\n",
// progname, version)
// fmt.Fprintf(os.Stderr, "{{.Desc}}\n")
// // fmt.Fprintf(os.Stderr, "Copyright (C) {{ date "Y4" }}, {{or $.Authors "The Author(s) <[email protected]>"}}\n\n")
// // err := ...
// // clis.WarnOn("Doing {{stringsTitle .Name}}", err)
// // or,
// // clis.AbortOn("Doing {{stringsTitle .Name}}", err)
// return nil
// }
Expand Down
15 changes: 7 additions & 8 deletions cli-std.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var root = &cli.Command{
{{if .Global}} Global: {{.Global}},
{{end}}{{if .Self}} Argv: func() interface{} { t := new(rootT); t.Self = t; return t },
{{else}} Argv: func() interface{} { return new(rootT) },
{{end}} Fn: {{.Name}},
{{end}} Fn: {{clk2uc .Name}},
{{if .NumOption}}
NumOption: {{.NumOption}},
{{end}}{{if .NumArg}}
Expand Down Expand Up @@ -72,9 +72,7 @@ var root = &cli.Command{

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

// func {{.Name}}(ctx *cli.Context) error {
// {{clk2uc .Name}} - main dispatcher dumb handler
// func {{clk2uc .Name}}(ctx *cli.Context) error {
// ctx.JSON(ctx.RootArgv())
// ctx.JSON(ctx.Argv())
// fmt.Println()
Expand All @@ -114,11 +113,11 @@ var root = &cli.Command{
//
// Do{{stringsTitle .Name}} implements the business logic of command `{{.Name}}`
// func Do{{stringsTitle .Name}}() error {
// fmt.Fprintf(os.Stderr,
// "%s v%s {{.Name}} - {{.Desc}}\n",
// progname, version)
// fmt.Fprintf(os.Stderr, "{{.Desc}}\n")
// // fmt.Fprintf(os.Stderr, "Copyright (C) {{ date "Y4" }}, {{or $.Authors "The Author(s) <[email protected]>"}}\n\n")
// // err := ...
// // clis.WarnOn("Doing {{stringsTitle .Name}}", err)
// // or,
// // clis.AbortOn("Doing {{stringsTitle .Name}}", err)
// return nil
// }
Expand Down
31 changes: 19 additions & 12 deletions wireframe_cliDef.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////////////////////
// Program: wireframe
// Purpose: wire framing
// Authors: Myself <[email protected]> (c) 2019, All rights reserved
// Authors: Myself <[email protected]> (c) 2021, All rights reserved
////////////////////////////////////////////////////////////////////////////

package main
Expand Down Expand Up @@ -34,11 +34,11 @@ type rootT struct {
var root = &cli.Command{
Name: "wireframe",
Desc: "wire framing\nVersion " + version + " built on " + date +
"\nCopyright (C) 2019, Myself <[email protected]>",
"\nCopyright (C) 2021, Myself <[email protected]>",
Text: "Tool to showcase wire-framing command line app fast prototype",
Global: true,
Argv: func() interface{} { t := new(rootT); t.Self = t; return t },
Fn: wireframe,
Fn: Wireframe,

NumArg: cli.AtLeast(1),
}
Expand All @@ -64,7 +64,7 @@ var root = &cli.Command{
// var (
// progname = "wireframe"
// version = "0.1.0"
// date = "2019-09-12"
// date = "2021-02-14"

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

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

// func wireframe(ctx *cli.Context) error {
// Wireframe - main dispatcher dumb handler
// func Wireframe(ctx *cli.Context) error {
// ctx.JSON(ctx.RootArgv())
// ctx.JSON(ctx.Argv())
// fmt.Println()
Expand All @@ -119,8 +118,12 @@ var root = &cli.Command{
//
// DoPut implements the business logic of command `put`
// func DoPut() error {
// fmt.Fprintf(os.Stderr, "%s v%s. put - Upload into service\n", progname, version)
// // fmt.Fprintf(os.Stderr, "Copyright (C) 2019, Myself <[email protected]>\n\n")
// fmt.Fprintf(os.Stderr, "Upload into service\n")
// // fmt.Fprintf(os.Stderr, "Copyright (C) 2021, Myself <[email protected]>\n\n")
// // err := ...
// // clis.WarnOn("Doing Put", err)
// // or,
// // clis.AbortOn("Doing Put", err)
// return nil
// }

Expand Down Expand Up @@ -155,8 +158,12 @@ var putDef = &cli.Command{
//
// DoGet implements the business logic of command `get`
// func DoGet() error {
// fmt.Fprintf(os.Stderr, "%s v%s. get - Get from the service\n", progname, version)
// // fmt.Fprintf(os.Stderr, "Copyright (C) 2019, Myself <[email protected]>\n\n")
// fmt.Fprintf(os.Stderr, "Get from the service\n")
// // fmt.Fprintf(os.Stderr, "Copyright (C) 2021, Myself <[email protected]>\n\n")
// // err := ...
// // clis.WarnOn("Doing Get", err)
// // or,
// // clis.AbortOn("Doing Get", err)
// return nil
// }

Expand Down
4 changes: 2 additions & 2 deletions wireframe_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"os"
"strings"

"github.com/mkideal/cli"
"github.com/labstack/gommon/color"
"github.com/mkideal/cli"
)

////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -62,7 +62,7 @@ func main() {
//==========================================================================
// Main dispatcher

func wireframe(ctx *cli.Context) error {
func Wireframe(ctx *cli.Context) error {
ctx.JSON(ctx.RootArgv())
ctx.JSON(ctx.Argv())
fmt.Println()
Expand Down

0 comments on commit 9dd4fe3

Please sign in to comment.