Skip to content

Commit dd77773

Browse files
committed
- [#] code gen switched from cli to go-flags
1 parent a1438c6 commit dd77773

1 file changed

Lines changed: 55 additions & 42 deletions

File tree

cc2py_cliDef.go

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,66 @@
11
////////////////////////////////////////////////////////////////////////////
22
// Program: cc2pyC
33
// Purpose: Chinese-Character to Pinyin converter
4-
// Authors: Tong Sun (c) 2016-2017, All rights reserved
4+
// Authors: Tong Sun (c) 2022, All rights reserved
55
////////////////////////////////////////////////////////////////////////////
66

77
package main
88

99
import (
10-
"github.com/mkideal/cli"
11-
clix "github.com/mkideal/cli/ext"
10+
// "fmt"
11+
// "os"
12+
13+
// "github.com/go-easygen/go-flags"
1214
)
1315

1416
////////////////////////////////////////////////////////////////////////////
15-
// cc2pyC
16-
17-
type rootT struct {
18-
cli.Helper
19-
Filei *clix.Reader `cli:"i,in" usage:"the Chinese text file to read from (or stdin)\n\t\t\tif not specified, read from command line instead"`
20-
Tone int `cli:"t,tone" usage:"tone selection\n\t\t\t 0: normal. mnemonic~ nothing\n\t\t\t 1: tone at the end. mnemonic~ single sided\n\t\t\t 2: tone after yunmu. mnemonic~ double sided\n\t\t\t 3: tone on yunmu. mnemonic~ fancy"`
21-
Truncate int `cli:"l,truncate" usage:"select only part of the pinyin\n\t\t\t 0: normal. mnemonic~ nothing truncated\n\t\t\t 1: leave first char. mnemonic~ one\n\t\t\t 2: leave first shengmu. mnemonic~ might be two\n\t\t\t 9: leave only yunmu. mnemonic~ last"`
22-
Separator string `cli:"s,separator" usage:"separator string between each pinyin" dft:" "`
23-
Polyphone bool `cli:"p,polyphone" usage:"polyphone support, output each polyphone pinyin available"`
24-
Capital bool `cli:"c,capitalized" usage:"capitalized each pinyin word"`
25-
}
26-
27-
var root = &cli.Command{
28-
Name: "cc2pyC",
29-
Desc: "Chinese-Character to Pinyin converter\nbuilt on " + buildTime,
30-
Text: "Converter Chinese to pinyin in different ways",
31-
Argv: func() interface{} { return new(rootT) },
32-
Fn: cc2pyC,
33-
34-
CanSubRoute: true,
35-
}
36-
37-
// func main() {
38-
// cli.SetUsageStyle(cli.ManualStyle) // up-down, for left-right, use NormalStyle
39-
// //NOTE: You can set any writer implements io.Writer
40-
// // default writer is os.Stdout
41-
// if err := cli.Root(root,).Run(os.Args[1:]); err != nil {
42-
// fmt.Fprintln(os.Stderr, err)
43-
// }
44-
// fmt.Println("")
45-
// }
46-
47-
// func cc2pyC(ctx *cli.Context) error {
48-
// ctx.JSON(ctx.RootArgv())
49-
// ctx.JSON(ctx.Argv())
50-
// fmt.Println()
51-
52-
// return nil
53-
// }
17+
// Constant and data type/structure definitions
18+
19+
// The OptsT type defines all the configurable options from cli.
20+
// type OptsT struct {
21+
// Filei string `short:"i" long:"in" description:"the Chinese text file to read from (or stdin)\n\t\t\tif not specified, read from command line instead"`
22+
// Tone int `short:"t" long:"tone" env:"CC2PY_TONE" description:"tone selection\n\t\t\t 0: normal. mnemonic~ nothing\n\t\t\t 1: tone at the end. mnemonic~ single sided\n\t\t\t 2: tone after yunmu. mnemonic~ double sided\n\t\t\t 3: tone on yunmu. mnemonic~ fancy"`
23+
// Truncate int `short:"l" long:"truncate" env:"CC2PY_TRUNCATE" description:"select only part of the pinyin\n\t\t\t 0: normal. mnemonic~ nothing truncated\n\t\t\t 1: leave first char. mnemonic~ one\n\t\t\t 2: leave first shengmu. mnemonic~ might be two\n\t\t\t 9: leave only yunmu. mnemonic~ last"`
24+
// Separator string `short:"s" long:"separator" env:"CC2PY_SEPARATOR" description:"separator string between each pinyin" default:" "`
25+
// Polyphone bool `short:"p" long:"polyphone" env:"CC2PY_POLYPHONE" description:"polyphone support, output each polyphone pinyin available"`
26+
// Capital bool `short:"c" long:"capitalized" env:"CC2PY_CAPITAL" description:"capitalized each pinyin word"`
27+
// }
28+
29+
// Template for main starts here
30+
31+
////////////////////////////////////////////////////////////////////////////
32+
// Global variables definitions
33+
34+
// var (
35+
// progname = "cc2pyC"
36+
// version = "0.1.0"
37+
// date = "2022-01-17"
38+
39+
// // Opts store all the configurable options
40+
// Opts OptsT
41+
// )
42+
//
43+
// var parser = flags.NewParser(&Opts, flags.Default)
44+
45+
////////////////////////////////////////////////////////////////////////////
46+
// Function definitions
47+
48+
// Function main
49+
// func main() {
50+
//
51+
// if _, err := parser.Parse(); err != nil {
52+
// switch flagsErr := err.(type) {
53+
// case flags.ErrorType:
54+
// if flagsErr == flags.ErrHelp {
55+
// os.Exit(0)
56+
// }
57+
// os.Exit(1)
58+
// default:
59+
// fmt.Println()
60+
// parser.WriteHelp(os.Stdout)
61+
// os.Exit(1)
62+
// }
63+
// }
64+
// fmt.Println("")
65+
// }
66+
// Template for main ends here

0 commit comments

Comments
 (0)