generated from gopherdojo/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargs.go
44 lines (38 loc) · 918 Bytes
/
args.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
package cli
import (
"fmt"
)
// Args represents CLI's arguments object
type Args struct {
DirecTory, From, To string
}
// Validate is a validation method
func (args *Args) Validate() error {
fileExtMap := createFileExtMap()
if _, ok := fileExtMap[args.From]; !ok {
return fmt.Errorf("argument of \"-f, --From\" is not valid file format. invalid format: %s", args.From)
}
if _, ok := fileExtMap[args.To]; !ok {
return fmt.Errorf("argument of \"-t, --To\" is not valid file format. invalid format: %s", args.To)
}
return nil
}
func createFileExtMap() map[string]string {
fileExtMap := make(map[string]string)
list := []string{
"jpg",
"jpeg",
"png",
"gif",
"bmp",
"tiff",
}
for _, v := range list {
fileExtMap[v] = ""
}
return fileExtMap
}
// NewArgs is a construcTor of Args
func NewArgs(DirecTory, From, To string) *Args {
return &Args{DirecTory: DirecTory, From: From, To: To}
}