Repository: benhoyt/goawk (go)

Issue:
Add support for --csv (which Gawk and onetrueawk are adding)
Gawk and BWK's onetrueawk are adding a `--csv` option (for the second edition of *The AWK Programming Language*), which I believe is equivalent to GoAWK's `-i csv`. We should confirm that and then add support for this argument to GoAWK for compatibility. Arnold said:

> In particular:
>        - Quoted fields are handled
>                - Including embedded CR-LF or CR or LF
>        - The record can be terminated by CR-LF or just LF
>        - In all cases, CR-LF becomes just LF by the time gawk sees the data


Pull request:
Add --csv option, in line with upcoming AWK and Gawk feature
Fixes #181 

Patch:
diff --git a/goawk.go b/goawk.go
index f7ca14f..e536ddc 100644
--- a/goawk.go
+++ b/goawk.go
@@ -51,6 +51,7 @@ const (
 	copyright  = "GoAWK " + version + " - Copyright (c) 2022 Ben Hoyt"
 	shortUsage = "usage: goawk [-F fs] [-v var=value] [-f progfile | 'prog'] [file ...]"
 	longUsage  = `Standard AWK arguments:
+  --csv             equivalent to "-i csv"
   -F separator      field separator (default " ")
   -f progfile       load AWK source from progfile (multiple allowed)
   -v var=value      variable assignment (multiple allowed)
@@ -158,6 +159,8 @@ argsLoop:
 			}
 			i++
 			cpuProfile = os.Args[i]
+		case "-csv", "--csv":
+			inputMode = "csv"
 		case "-d":
 			debug = true
 		case "-da":


Test patch:
diff --git a/goawk_test.go b/goawk_test.go
index 1eb740a..09cf193 100644
--- a/goawk_test.go
+++ b/goawk_test.go
@@ -624,6 +624,8 @@ func TestGoAWKSpecificOptions(t *testing.T) {
 		{[]string{"-icsv", `{ print $2, $1 }`}, "Bob,42\nJane,37", "42 Bob\n37 Jane\n", ""},
 		{[]string{"-i", "csv", `{ print $2, $1 }`}, "Bob,42\nJane,37", "42 Bob\n37 Jane\n", ""},
 		{[]string{"-icsv", "-H", "-ocsv", `{ print @"age", @"name" }`}, "name,age\n\"Bo,ba\",42\nJane,37", "42,\"Bo,ba\"\n37,Jane\n", ""},
+		{[]string{"-csv", `{ print $2, $1 }`}, "Bob,42\nJane,37", "42 Bob\n37 Jane\n", ""},
+		{[]string{"--csv", `{ print $2, $1 }`}, "Bob,42\nJane,37", "42 Bob\n37 Jane\n", ""},
 		{[]string{"-o", "csv", `BEGIN { print "foo,bar", 3.14, "baz" }`}, "", "\"foo,bar\",3.14,baz\n", ""},
 		{[]string{"-iabc", `{}`}, "", "", "invalid input mode \"abc\"\n"},
 		{[]string{"-oxyz", `{}`}, "", "", "invalid output mode \"xyz\"\n"},