@@ -22,7 +22,8 @@ const IMAGE_URL_COL = 21
22
22
const PRODUCT_NAME_COL = 6
23
23
const PRICE_COL = 14
24
24
25
- var purge bool
25
+ var purgeOnly bool
26
+ var verbose bool
26
27
27
28
type TemplateVariable struct {
28
29
Key string `yaml:"key"`
@@ -41,7 +42,8 @@ type NercConf struct {
41
42
}
42
43
43
44
func main () {
44
- flag .BoolVar (& purge , "purge" , false , "Purge all existing files from output directory." )
45
+ flag .BoolVar (& purgeOnly , "purge" , false , "Purge all existing files from output directory and stop." )
46
+ flag .BoolVar (& verbose , "v" , false , "Use verbose output." )
45
47
flag .Parse ()
46
48
47
49
nercConf := NercConf {}
@@ -61,24 +63,29 @@ func main() {
61
63
if _ , err := os .Stat (nercConf .Input ); os .IsNotExist (err ) {
62
64
fmt .Println ("Could not find '" + nercConf .Input + "'. Specify input file with -i=<filepath>." )
63
65
} else {
64
- fmt .Println ("Reading input file: " + nercConf .Input )
65
- csvFile , _ := os .Open (nercConf .Input )
66
- r := csv .NewReader (bufio .NewReader (csvFile ))
66
+ purgeOutput (nercConf , ! verbose )
67
67
68
- if purge {
69
- fmt .Println ("Purging output directory..." )
70
- err := os .RemoveAll (nercConf .Output )
71
- if err != nil {
72
- fmt .Println (err )
73
- }
68
+ if purgeOnly {
69
+ fmt .Println ("Purged output directory" )
70
+ } else {
71
+ fmt .Println ("Reading input file: " + nercConf .Input )
72
+ csvFile , _ := os .Open (nercConf .Input )
73
+ r := csv .NewReader (bufio .NewReader (csvFile ))
74
+ os .Mkdir (nercConf .Output , os .ModePerm )
75
+ csvToConfigs (r , nercConf )
74
76
}
75
- os .Mkdir (nercConf .Output , os .ModePerm )
76
- csvToConfigs (r , nercConf )
77
77
}
78
78
79
79
fmt .Println ("Done" )
80
80
}
81
81
82
+ func purgeOutput (nercConf NercConf , silent bool ) {
83
+ err := os .RemoveAll (nercConf .Output )
84
+ if err != nil && ! silent {
85
+ fmt .Println (err )
86
+ }
87
+ }
88
+
82
89
// process applies the data structure 'vars' onto an already
83
90
// parsed template 't', and returns the resulting string.
84
91
func process (t * template.Template , vars interface {}) string {
0 commit comments