/
inputs.go
144 lines (126 loc) · 3.08 KB
/
inputs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package prog
import (
"errors"
"flag"
"fmt"
"os"
)
type modeType struct {
isCli *bool
}
type templateFileType struct {
name *string
}
type outDirType struct {
name *string
}
type outFileNameType struct {
name *string
}
type dataFileType struct {
name *string
}
var (
ShowVersion bool
Mode modeType
TemplateFile templateFileType
OutDir outDirType
OutFileName outFileNameType
DataFile dataFileType
)
// Methods of modeType
func (t *modeType) Set(isCli *bool) {
t.isCli = isCli
}
func (t *modeType) IsCli() bool {
return *t.isCli
}
func (t *modeType) Init() error {
return nil
}
// Methods of templateFileType
func (t *templateFileType) Set(name *string) {
t.name = name
}
func (t *templateFileType) Name() string {
return *t.name
}
func (t *templateFileType) Init() error {
if len(*t.name) == 0 {
return errors.New("Template file is not specified.")
}
*t.name = normalizePath(*t.name)
return fileExists(t.Name())
}
// Methods of outDirType
func (t *outDirType) Set(name *string) {
t.name = name
}
func (t *outDirType) Name() string {
return *t.name
}
func (t *outDirType) Init() error {
*t.name = normalizePath(*t.name)
return dirExists(t.Name(), true)
}
// Methods of outFileNameType
func (t *outFileNameType) Set(name *string) {
t.name = name
}
func (t *outFileNameType) Name() string {
return *t.name
}
func (t *outFileNameType) Init() error {
if len(*t.name) == 0 {
return errors.New("Output file name is not specified.")
}
*t.name = normalizePath(*t.name)
return nil
}
// Methods of dataFileType
func (t *dataFileType) Set(name *string) {
t.name = name
}
func (t *dataFileType) Name() string {
return *t.name
}
func (t *dataFileType) Init() error {
if len(*t.name) == 0 {
return errors.New("Excel data file is not specified.")
}
*t.name = normalizePath(*t.name)
return fileExists(t.Name())
}
func InitUsage() {
usageTemplateFile := `Template file that contains patterns to be replaced by excel data:
[COLUMN]:
Replaces with the content of corresponding column from excel data
For example:
[A] replaces with the data of cell "A" of current row
Patterns can be escaped by adding ":" after "["
For example:
[:A] generates [A]`
usageOutFileName := `Output file name that contains special patterns:
[0000]:
Generates auto increment number padded to the specified zeros
For example:
[00].txt generates: 00.txt, 01.txt, 02.txt, 03.txt, ...
[COLUMN]:
Replaces with the content of corresponding column from excel data
For example:
[A].txt replaces [A] with the data of cell "A" of current row
Patterns can be escaped by adding ":" after "["
For example:
[:00].txt generates [00].txt`
Mode.Set(flag.Bool("c", false, "Run in CLI mode and do not open GUI"))
TemplateFile.Set(flag.String("t", "", usageTemplateFile))
OutDir.Set(flag.String("o", "out", "Output directory"))
OutFileName.Set(flag.String("f", "[0000].txt", usageOutFileName+"\n"))
DataFile.Set(flag.String("d", "", "Excel data file"))
v := flag.Bool("v", false, "Version number")
flag.Parse()
if *v {
fmt.Printf("Version: %v\n", VERSION)
os.Exit(0)
}
}