-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathargs.go
69 lines (54 loc) · 1.59 KB
/
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
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
package ngos
import (
"errors"
"flag"
"fmt"
"os"
)
const (
// Version , the version of Ngos
Version = "0.0.0"
)
// Arguments struct will hold flag and arguments from stdin
type Arguments struct {
OldCSVFile string
NewCSVFile string
OutputCSVFile string
ShowVersion bool
Help func()
}
// ParseArgs function, this function will parse flag and arguments from stdin to Argumetns struct
func ParseArgs() (*Arguments, error) {
var (
oldCSVFile string
newCSVFile string
ouputCSVFile string
showVersion bool
)
flag.StringVar(&oldCSVFile, "old", "old.csv", "old CSV file")
flag.StringVar(&newCSVFile, "new", "new.csv", "new CSV file")
flag.StringVar(&ouputCSVFile, "output", "output_diff.csv", "output CSV file")
flag.StringVar(&ouputCSVFile, "o", "output_diff.csv", "output CSV file")
flag.BoolVar(&showVersion, "version", false, "show version")
flag.BoolVar(&showVersion, "v", false, "show version")
flag.Usage = func() {
fmt.Fprintln(os.Stderr, " -old | --old", "old CSV file")
fmt.Fprintln(os.Stderr, " -new | --new", "new CSV file")
fmt.Fprintln(os.Stderr, " -o | --o", "output CSV file")
fmt.Fprintln(os.Stderr, " -v | --version", "show ngos version")
}
flag.Parse()
if len(oldCSVFile) <= 0 {
return &Arguments{Help: flag.Usage}, errors.New(" (-old) arg required")
}
if len(newCSVFile) <= 0 {
return &Arguments{Help: flag.Usage}, errors.New(" (-new) arg required")
}
return &Arguments{
OldCSVFile: oldCSVFile,
NewCSVFile: newCSVFile,
OutputCSVFile: ouputCSVFile,
ShowVersion: showVersion,
Help: flag.Usage,
}, nil
}