microsoft / go-sqlcmd

The new sqlcmd, CLI for SQL Server and Azure SQL (winget install sqlcmd / sqlcmd create mssql / sqlcmd open ads)
https://learn.microsoft.com/sql/tools/sqlcmd/go-sqlcmd-utility
MIT License
338 stars 60 forks source link

Modern CLI is getting invoked in spite of missing verbs #183

Closed apoorvdeshmukh closed 1 year ago

apoorvdeshmukh commented 1 year ago

@JyotikaGargg and I found this issue in main.go where we read the 2nd argument even if os.Args contains just 1 argument i.e. when no argument is specified to sqlcmd.exe

if len(os.Args) > 0 {
        if rootCmd.IsValidSubCommand(os.Args[1]) {
            isNewCliCommand = true
        }
    }
\go-sqlcmd\cmd\modern>go build -o sqlcmd.exe
\go-sqlcmd\cmd\modern>.\sqlcmd.exe
panic: runtime error: index out of range [1] with length 1

goroutine 1 [running]:
main.isFirstArgModernCliSubCommand(...)
        C:/Users/apdeshmukh/git/go-sqlcmd/cmd/modern/main.go:53
main.main()
        C:/Users/apdeshmukh/git/go-sqlcmd/cmd/modern/main.go:41 +0x245
stuartpa commented 1 year ago

Yeah, I saw this as well (have a fix for it in my draft PR). Thanks for fixing it