Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 31, 2026

sqlcmd -h returns "Missing argument" error because -h expects 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:

  • Added preprocessHelpFlags() that converts -h to -? when not followed by a number
  • Converts -help to --help (avoids shell parsing issues)
  • Preserves -h <number> for backward compatibility with header count flag
// Before: sqlcmd -h → "Missing argument" error
// After:  sqlcmd -h → shows help
//         sqlcmd -h 10 → sets header count (unchanged)
//         sqlcmd -help → shows help

Test coverage in cmd/sqlcmd/sqlcmd_test.go:

  • Conversion logic tests (7 cases)
  • End-to-end parsing tests (3 cases)
  • Validates both help behavior and backward compatibility

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • learn.microsoft.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>sqlcmd -? and sqlcmd -h are not working as expected</issue_title>
<issue_description>I am on macOS, zsh shell.

~ % sqlcmd -h
Sqlcmd: '-h': Missing argument. Enter '-?' for help.

~ % sqlcmd -?
zsh: no matches found: -?

sqlcmd --help gives the expected output.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits January 31, 2026 19:52
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
Copilot AI requested a review from dlevy-msft-sql January 31, 2026 20:01
@dlevy-msft-sql dlevy-msft-sql added bug Something isn't working sqlcmd switch switch in existing sqlcmd Size: S Small issue (less than one week effort) needs-work labels Feb 1, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 -h to -? when not followed by a number, preserving backward compatibility with -h <number> for setting header count
  • Converts -help to --help to avoid shell parsing issues (since -help would 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)

Comment on lines +358 to +368

// If -h is followed by a number, keep it as-is (header count)
// Otherwise, convert to -? (show help)
if !nextIsNumber {
result = append(result, "-?")
} else {
result = append(result, arg)
}
continue
}

Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When -h is followed by a non-numeric argument (e.g., sqlcmd -h abc), the conversion to -? preserves the non-numeric argument, which will later cause an "Unknown command" error (line 242-244) instead of showing help. Consider consuming/ignoring the non-numeric argument when converting -h to help mode, so that sqlcmd -h abc shows help rather than an error about "abc".

Suggested change
// If -h is followed by a number, keep it as-is (header count)
// Otherwise, convert to -? (show help)
if !nextIsNumber {
result = append(result, "-?")
} else {
result = append(result, arg)
}
continue
}
// If -h is followed by a number, keep it as-is (header count)
// Otherwise, convert to -? (show help) and consume any non-numeric argument
if !nextIsNumber {
result = append(result, "-?")
// If there was a following non-numeric argument, consume it
if hasNextArg {
i++
}
} else {
result = append(result, arg)
}
continue
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working needs-work Size: S Small issue (less than one week effort) sqlcmd switch switch in existing sqlcmd

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlcmd -? and sqlcmd -h are not working as expected

2 participants