feat: add -f codepage flag for input/output encoding by dlevy-msft-sql · Pull Request #638 · microsoft/go-sqlcmd
pkg/sqlcmd/sqlcmd_test.go
Adds tests to verify IncludeFile decodes input files correctly under various input code pages (Windows-1252, UTF-16LE/BE with and without BOM).
pkg/sqlcmd/sqlcmd.go
Extends Sqlcmd with a CodePage field and updates IncludeFile to select an appropriate io.Reader based on configured input code page or BOM auto-detection.
pkg/sqlcmd/commands_test.go
Adds tests confirming :OUT and :ERROR commands honor the configured output code page when writing to files.
pkg/sqlcmd/commands.go
Introduces a transformWriteCloser helper and updates :OUT/:ERROR commands to encode output using the selected code page while ensuring underlying files are closed correctly.
pkg/sqlcmd/codepage_windows.go
Implements Windows-specific encoding.Encoding support backed by MultiByteToWideChar/WideCharToMultiByte for system-installed code pages not in the built-in registry.
pkg/sqlcmd/codepage_test.go
Adds tests for ParseCodePage, GetEncoding, SupportedCodePages, and Windows-specific fallback behavior, including round-trip checks for a Windows-only EBCDIC code page.
pkg/sqlcmd/codepage_other.go
Provides a non-Windows implementation of getSystemCodePageEncoding that surfaces a clear error for unsupported system code pages.
pkg/sqlcmd/codepage.go
Defines the cross-platform code page registry, CodePageSettings, parsing/validation logic for -f, and a SupportedCodePages API used by the CLI.
cmd/sqlcmd/sqlcmd_test.go
Extends CLI argument tests to cover -f / --code-page, --list-codepages, and various invalid code page argument combinations.
cmd/sqlcmd/sqlcmd.go
Adds CodePage and ListCodePages arguments, validates and stores parsed CodePageSettings, applies them to the Sqlcmd instance, and implements --list-codepages output formatting.
README.md
Documents the new -f flag, describes supported code pages, provides usage examples, and explains --list-codepages and default BOM auto-detection behavior.