Skip to content

Running cmd.Do twice will cause a panic due to redefined flag #1616

Closed
@jlisthood

Description

@jlisthood

Version

1.13.0

What happened?

I have a script that runs sqlc's internal cmd.Do function multiple times to generate sqlc across multiple folders in a monorepo. However, since version 1.13, we cannot run cmd.Do multiple times without the program panicking.

This is reproable by doing this:

package main

import (
        "os"
	"github.com/kyleconroy/sqlc/internal/cmd"
)

func main() {
       cmd.Do(os.Args[1:], os.Stdin, os.Stdout, os.Stderr)
       cmd.Do(os.Args[1:], os.Stdin, os.Stdout, os.Stderr) // this panics
}

Relevant log output

panic: upload flag redefined: dry-run

goroutine 1 [running]:
github.com/spf13/pflag.(*FlagSet).AddFlag(0xc0005b1300, 0xc0001243c0)
        external/com_github_spf13_pflag/flag.go:848 +0x825
github.com/spf13/pflag.(*FlagSet).VarPF(0xc0005b1300, 0x5122970, 0xc0005cef19, 0x4e6bd3d, 0x7, 0x0, 0x0, 0x4e9006b, 0x24, 0xc0005cef19)
        external/com_github_spf13_pflag/flag.go:831 +0x10b
github.com/spf13/pflag.(*FlagSet).BoolVarP(0xc0005b1300, 0xc0005cef19, 0x4e6bd3d, 0x7, 0x0, 0x0, 0x0, 0x4e9006b, 0x24)
        external/com_github_spf13_pflag/bool.go:55 +0x97
github.com/spf13/pflag.(*FlagSet).BoolP(...)
        external/com_github_spf13_pflag/bool.go:80
github.com/kyleconroy/sqlc/internal/cmd.Do(0xc00003c210, 0x0, 0x0, 0x5119220, 0xc000010010, 0x5119260, 0xc000010018, 0x5119260, 0xc000010020, 0x0)
        external/com_github_kyleconroy_sqlc/internal/cmd/cmd.go:32 +0x2e5
main.main()

Database schema

issue is an internal cmd error and agnostic to schema

SQL queries

issue is an internal cmd error and agnostic to sql queries

Configuration

issue is an internal cmd error and agnostic to configuration

Playground URL

No response

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions