Fix -h and -help flags to show help instead of requiring arguments#683
Closed
Fix -h and -help flags to show help instead of requiring arguments#683
Conversation
Co-authored-by: dlevy-msft-sql <194277063+dlevy-msft-sql@users.noreply.github.com>
- Convert -h without an argument to -? to show help - Keep -h with a numeric argument for setting header count (e.g., -h 10, -h -1) - Convert -help to --help to show help - Add comprehensive tests for the new behavior Co-authored-by: dlevy-msft-sql <194277063+dlevy-msft-sql@users.noreply.github.com>
- Remove trailing whitespace from preprocessHelpFlags function - Restore NOTICE.md that was accidentally modified by build process Co-authored-by: dlevy-msft-sql <194277063+dlevy-msft-sql@users.noreply.github.com>
- Remove unnecessary blank lines in convertOsArgs and preprocessHelpFlags - Add test case for -h followed by non-numeric value Co-authored-by: dlevy-msft-sql <194277063+dlevy-msft-sql@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix sqlcmd -? and sqlcmd -h functionality issues
Fix -h and -help flags to show help instead of requiring arguments
Jan 31, 2026
There was a problem hiding this comment.
Pull request overview
This PR fixes the behavior of the -h and -help flags to show help instead of requiring arguments, addressing issue #604 where sqlcmd -h returned a "Missing argument" error and sqlcmd -? requires quoting in zsh due to glob expansion.
Changes:
- Added
preprocessHelpFlags()function that converts-hto-?when not followed by a number, preserving backward compatibility with-h <number>for setting header count - Converts
-helpto--helpto avoid shell parsing issues (since-helpwould be parsed as-h elp) - Added comprehensive test coverage for the new conversion logic and end-to-end parsing behavior
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| cmd/sqlcmd/sqlcmd.go | Implements preprocessHelpFlags() function with logic to detect numeric vs non-numeric arguments following -h, and integrates it into the argument preprocessing pipeline |
| cmd/sqlcmd/sqlcmd_test.go | Adds 10 new test cases covering conversion logic (7 tests in TestConvertOsArgs) and end-to-end parsing behavior (3 tests in TestValidCommandLineToArgsConversion) |
Contributor
|
@copilot fix the review items |
When -h is followed by a non-numeric argument that is not a flag (e.g., 'abc'), consume it to prevent "Unknown command" errors. Flags are preserved for normal processing (e.g., -h -E converts to -? -E, not just -?). This addresses PR review feedback to improve user experience. Co-authored-by: dlevy-msft-sql <194277063+dlevy-msft-sql@users.noreply.github.com>
dlevy-msft-sql
approved these changes
Feb 2, 2026
Contributor
|
Replaced by cleaner implementation in #707 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix -h and -help flags to show help instead of requiring arguments
sqlcmd -hreturns "Missing argument" error because-hexpects an integer for header count. Additionally,-?requires quoting in zsh due to glob expansion, making help discovery difficult.Changes
Argument preprocessing in
cmd/sqlcmd/sqlcmd.go:preprocessHelpFlags()that converts-hto-?when not followed by a number-helpto--help(avoids shell parsing issues)-h <number>for backward compatibility with header count flag-hto prevent "Unknown command" errorsTest coverage in
cmd/sqlcmd/sqlcmd_test.go:Verification
✅ All tests pass
✅
sqlcmd -h abcnow shows help (instead of "Unknown command" error)✅
sqlcmd -h -Eshows help and preserves-Eflag✅ Backward compatibility maintained:
sqlcmd -h 10still sets header countOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.