From 9dd4fe3a1e408c752861ae2a70c1f262bd7e93e5 Mon Sep 17 00:00:00 2001 From: Tong Sun Date: Sun, 14 Feb 2021 20:46:28 -0500 Subject: [PATCH] - [*] regulate main dispatcher name too --- cli-ext.tmpl | 15 +++++++-------- cli-std.tmpl | 15 +++++++-------- wireframe_cliDef.go | 31 +++++++++++++++++++------------ wireframe_main.go | 4 ++-- 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/cli-ext.tmpl b/cli-ext.tmpl index e1e657c..377485f 100644 --- a/cli-ext.tmpl +++ b/cli-ext.tmpl @@ -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}} @@ -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) @@ -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() @@ -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) "}}\n\n") // // err := ... +// // clis.WarnOn("Doing {{stringsTitle .Name}}", err) +// // or, // // clis.AbortOn("Doing {{stringsTitle .Name}}", err) // return nil // } diff --git a/cli-std.tmpl b/cli-std.tmpl index dd5da40..e305c42 100644 --- a/cli-std.tmpl +++ b/cli-std.tmpl @@ -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}} @@ -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) @@ -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() @@ -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) "}}\n\n") // // err := ... +// // clis.WarnOn("Doing {{stringsTitle .Name}}", err) +// // or, // // clis.AbortOn("Doing {{stringsTitle .Name}}", err) // return nil // } diff --git a/wireframe_cliDef.go b/wireframe_cliDef.go index acea29a..0abc131 100644 --- a/wireframe_cliDef.go +++ b/wireframe_cliDef.go @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////////////////////// // Program: wireframe // Purpose: wire framing -// Authors: Myself (c) 2019, All rights reserved +// Authors: Myself (c) 2021, All rights reserved //////////////////////////////////////////////////////////////////////////// package main @@ -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 ", + "\nCopyright (C) 2021, Myself ", 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), } @@ -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 @@ -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 { @@ -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() @@ -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 \n\n") +// fmt.Fprintf(os.Stderr, "Upload into service\n") +// // fmt.Fprintf(os.Stderr, "Copyright (C) 2021, Myself \n\n") +// // err := ... +// // clis.WarnOn("Doing Put", err) +// // or, +// // clis.AbortOn("Doing Put", err) // return nil // } @@ -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 \n\n") +// fmt.Fprintf(os.Stderr, "Get from the service\n") +// // fmt.Fprintf(os.Stderr, "Copyright (C) 2021, Myself \n\n") +// // err := ... +// // clis.WarnOn("Doing Get", err) +// // or, +// // clis.AbortOn("Doing Get", err) // return nil // } diff --git a/wireframe_main.go b/wireframe_main.go index 012be4b..7238361 100644 --- a/wireframe_main.go +++ b/wireframe_main.go @@ -13,8 +13,8 @@ import ( "os" "strings" - "github.com/mkideal/cli" "github.com/labstack/gommon/color" + "github.com/mkideal/cli" ) //////////////////////////////////////////////////////////////////////////// @@ -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()