Skip to content

Commit 241faeb

Browse files
committed
- [+] add _opt.go, based on new template
1 parent b2b9b5b commit 241faeb

4 files changed

Lines changed: 71 additions & 45 deletions

File tree

cc2py_cli.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Options:
1212
- Name: Filei
1313
Type: string
1414
Flag: "i,in"
15-
Usage: 'the Chinese text file to read from (or "-" for stdin)'
15+
Usage: 'the Chinese text file to read from (or \"-\" for stdin)'
1616

1717
- Name: Tone
1818
Type: int
@@ -46,8 +46,8 @@ Options:
4646
Usage: capitalized each pinyin word
4747

4848
- Name: Args
49-
Args: |
49+
Args: |-
5050
// positional arguments
51-
// Args struct {
52-
// CCStrs []string
53-
// } `positional-args:"yes" required:"yes"`
51+
// Args struct {
52+
// CCStrs []string
53+
// } `positional-args:"yes" required:"yes"`

cc2py_cliDef.go

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,18 @@ import (
1313
// "github.com/go-easygen/go-flags"
1414
)
1515

16-
////////////////////////////////////////////////////////////////////////////
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 "-" for stdin)"`
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-
// // positional arguments
29-
// Args struct {
30-
// CCStrs []string
31-
// } `positional-args:"yes" required:"yes"`
32-
33-
// }
34-
3516
// Template for main starts here
3617

18+
//////////////////////////////////////////////////////////////////////////
19+
// Constant and data type/structure definitions
20+
3721
////////////////////////////////////////////////////////////////////////////
3822
// Global variables definitions
3923

4024
// var (
4125
// progname = "cc2py"
4226
// version = "0.1.0"
43-
// date = "2022-01-17"
27+
// date = "2022-01-18"
4428

4529
// // Opts store all the configurable options
4630
// Opts OptsT
@@ -55,9 +39,36 @@ import (
5539
// func main() {
5640
//
5741
// if _, err := parser.Parse(); err != nil {
42+
// fmt.Println()
5843
// parser.WriteHelp(os.Stdout)
5944
// os.Exit(1)
6045
// }
61-
// fmt.Println("")
46+
// fmt.Println()
47+
// //DoCc2py()
6248
// }
6349
// Template for main ends here
50+
51+
// DoCc2py implements the business logic of command `cc2py`
52+
// func DoCc2py() error {
53+
// return nil
54+
// }
55+
56+
// Template for type define starts here
57+
////////////////////////////////////////////////////////////////////////////
58+
// Constant and data type/structure definitions
59+
60+
// The OptsT type defines all the configurable options from cli.
61+
// type OptsT struct {
62+
// Filei string `short:"i" long:"in" description:"the Chinese text file to read from (or \"-\" for stdin)"`
63+
// 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"`
64+
// 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"`
65+
// Separator string `short:"s" long:"separator" env:"CC2PY_SEPARATOR" description:"separator string between each pinyin" default:" "`
66+
// Polyphone bool `short:"p" long:"polyphone" env:"CC2PY_POLYPHONE" description:"polyphone support, output each polyphone pinyin available"`
67+
// Capital bool `short:"c" long:"capitalized" env:"CC2PY_CAPITAL" description:"capitalized each pinyin word"`
68+
//
69+
// // positional arguments
70+
// Args struct {
71+
// CCStrs []string
72+
// } `positional-args:"yes" required:"yes"`
73+
// }
74+
// Template for type define ends here

cc2py_main.go

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,13 @@ import (
2222
////////////////////////////////////////////////////////////////////////////
2323
// Constant and data type/structure definitions
2424

25-
// The OptsT type defines all the configurable options from cli.
26-
type OptsT struct {
27-
Filei string `short:"i" long:"in" description:"the Chinese text file to read from (or \"-\" for stdin)"`
28-
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"`
29-
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"`
30-
Separator string `short:"s" long:"separator" env:"CC2PY_SEPARATOR" description:"separator string between each pinyin" default:" "`
31-
Polyphone bool `short:"p" long:"polyphone" env:"CC2PY_POLYPHONE" description:"polyphone support, output each polyphone pinyin available"`
32-
Capital bool `short:"c" long:"capitalized" env:"CC2PY_CAPITAL" description:"capitalized each pinyin word"`
33-
34-
// positional arguments
35-
Args struct {
36-
CCStrs []string
37-
} `positional-args:"yes" required:"yes"`
38-
}
39-
4025
////////////////////////////////////////////////////////////////////////////
4126
// Global variables definitions
4227

4328
var (
44-
progname = "cc2py"
45-
version = "0.2.2"
46-
date = "2022-01-18"
29+
progname = "cc2py"
30+
version = "0.2.2"
31+
date = "2022-01-18"
4732

4833
// Opts store all the configurable options
4934
Opts OptsT
@@ -61,9 +46,14 @@ func main() {
6146
os.Exit(1)
6247
}
6348
fmt.Println("")
49+
DoCc2py()
50+
}
51+
52+
// DoCc2py implements the business logic of command `cc2py`
53+
func DoCc2py() error {
6454
err := Validate()
6555
abortOn("cli options", err)
66-
cc2pyC()
56+
return cc2pyC()
6757
}
6858

6959
// Validate cli values sanity

cc2py_opt.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
////////////////////////////////////////////////////////////////////////////
2+
// Program: cc2py
3+
// Purpose: Chinese-Character to Pinyin converter
4+
// Authors: Tong Sun (c) 2022, All rights reserved
5+
////////////////////////////////////////////////////////////////////////////
6+
7+
package main
8+
9+
////////////////////////////////////////////////////////////////////////////
10+
// Constant and data type/structure definitions
11+
12+
// The OptsT type defines all the configurable options from cli.
13+
type OptsT struct {
14+
Filei string `short:"i" long:"in" description:"the Chinese text file to read from (or \"-\" for stdin)"`
15+
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"`
16+
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"`
17+
Separator string `short:"s" long:"separator" env:"CC2PY_SEPARATOR" description:"separator string between each pinyin" default:" "`
18+
Polyphone bool `short:"p" long:"polyphone" env:"CC2PY_POLYPHONE" description:"polyphone support, output each polyphone pinyin available"`
19+
Capital bool `short:"c" long:"capitalized" env:"CC2PY_CAPITAL" description:"capitalized each pinyin word"`
20+
21+
// positional arguments
22+
Args struct {
23+
CCStrs []string
24+
} `positional-args:"yes" required:"yes"`
25+
}

0 commit comments

Comments
 (0)