Build a command-line tool that profiles a CSV file. For every column it infers a type and reports row, null, and distinct counts, the minimum and maximum, and for numeric columns the sum, mean, and median. It also lists the most frequent values of one column. Implement in Go 1.22 or newer using only the standard library. The application root is a Go module, and its executable is the main package at `./cmd/csvstat`. Tests run under `go test`. The harness runs `go build -o ./cmd/csvstat` and then runs 22 checks. Each check compares one command's exit code and standard output with a known answer. Options precede the file. Exactly one file is required. | `--column ` | Profile only the named column. | | `--freq ` | List the most frequent values of the named column instead of profiling. | | `--top ` | With `--freq`, list at most `` values. A positive integer; default `5`. | `--column` and `--freq` cannot be combined. `--top` is valid only with `--freq`. The file is UTF-8 CSV as RFC 4180 defines it, read with Go's `encoding/csv`. The first record is the header. Every header name and every value is trimmed of leading and trailing spaces before any other rule applies. The file is **rejected** when it is empty, when a header name is empty or repeated, or when any record has a different number of fields from the header. **Null.** A value is null when it is empty, or when it equals `NA`, `N/A`, or `NULL` ignoring case. All other values are non-null. | `integer` | matches `-?[0-9]+` | | `number` | matches `-?[0-9]+(\.[0-9]+)?` | | `date` | matches `YYYY-MM-DD` and is a real calendar date (`2025-02-30` is not) | | `boolean` | equals `true` or `false`, ignoring case | | `text` | anything | A column with no non-null values has type `empty`. | `rows` | Number of data records. | | `nulls` | Number of null values. | | `distinct` | Number of different non-null values, compared as exact strings after trimming. | | `min`, `max` | `integer`: the smallest and largest value as an integer. `number`: as a decimal. `date`: earliest and latest. `boolean`: `false` if any value is false, else `true`; `true` if any value is true, else `false`. `text`: smallest and largest by byte value. `empty`: empty. | | `sum` | `integer`: the integer total. `number`: the decimal total. Otherwise empty. | | `mean` | `integer` and `number`: total divided by non-null count. Otherwise empty. | | `median` | `integer` and `number`: the middle value of the sorted non-null values, or the mean of the two middle values when the count is even. Otherwise empty. | **Decimals.** Every `number` `min`, `max`, and `sum`, and every `mean` and `median`, is written with exactly two decimal places, rounded half away from zero from the exact value, with a leading `-` when negative and no thousands separator: `1012.50`, `-12.21`, `0.00`. Integer `min`, `max`, and `sum` are written as plain integers. Header `column,type,rows,nulls,distinct,min,max,sum,mean,median`, then one row per column in file order (or the one named by `--column`). Header `value,count`, then one row per distinct non-null value of the column, ordered by count descending, then value ascending by byte value, at most `--top` rows. Null values are not listed. A column with no non-null values writes only the header. CSV on standard output with `\n` line endings. A field that contains a comma, a double quote, or a newline is quoted as RFC 4180 specifies; Go's `encoding/csv` writer produces this format. A failing command writes nothing to standard output and one diagnostic line to standard error naming the file and, for a rejected record, its line number. | `1` | Operational failure: the file cannot be opened or read. | | `2` | Usage error: missing or extra file, unknown option, missing option value, `--top` not a positive integer, `--top` without `--freq`, `--column` with `--freq`. | | `3` | Rejected: empty file, empty or repeated header name, ragged record, or a column name that is not in the header. | The completed application provides a POSIX-compatible `bin/test.sh` that runs `go vet ./...` and `go test ./...` from the application root and exits zero only when both pass. The suite covers each type, each statistic, null handling, rounding, each output form, and each exit code using files written by the tests.