diff --git a/README.md b/README.md index 5b5f1fb..336f7f1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # csvToCamt Convert CSV correction files to CAMT format -Get binaries from [release page](https://github.com/krishnaprasadmg/csvToCamt/releases/tag/v0.1.3) +Get binaries from [release page](https://github.com/krishnaprasadmg/csvToCamt/releases) # Example @@ -10,3 +10,5 @@ Execute the command with config file (see [sample](config.yaml)) and CSV correct ``` $./csvToCamt -c config.yaml q3.csv q4.csv ``` + +Optionally use the `-s` flag to skip the headers from CSV files (If the CSVs have headers) \ No newline at end of file diff --git a/main.go b/main.go index cb3e14c..df1a03c 100644 --- a/main.go +++ b/main.go @@ -18,7 +18,9 @@ func init() { func main() { var configFile string + var skipHeader bool flag.StringVar(&configFile, "c", "", "Config file to use, see config.yaml for example") + flag.BoolVar(&skipHeader, "s", false, "Skip CSV header lines, off by default") flag.Parse() if configFile == "" || len(flag.Args()) == 0 { @@ -29,7 +31,7 @@ func main() { utils.ParseConfigFile(configFile) - investorData := utils.LoadInvestors(flag.Args()) + investorData := utils.LoadInvestors(flag.Args(), skipHeader) transactionData, totalAmount := utils.BuildTransactions(investorData) camtDoc := utils.NewCamtDocument() diff --git a/utils/investor.go b/utils/investor.go index 675f685..e6bd62c 100644 --- a/utils/investor.go +++ b/utils/investor.go @@ -17,7 +17,7 @@ type Investor struct { amount float64 } -func LoadInvestors(files []string) []Investor { +func LoadInvestors(files []string, skipHeader bool) []Investor { var amount float64 investors := make([]Investor, 0) @@ -26,13 +26,19 @@ func LoadInvestors(files []string) []Investor { PanicOnError(err) defer investorFile.Close() + line := 0 reader := csv.NewReader(investorFile) reader.Comma = ';' reader.FieldsPerRecord = 3 for { + line++ record, err := reader.Read() + if line == 1 && skipHeader { + continue + } + if err == io.EOF { break } else if err != nil {