Documentation
¶
Overview ¶
Package cli holds the command-line plumbing that pggen and chgen share.
The two binaries stay separate because they target different databases with different drivers and different parameter syntax. What they do with the flags, though, is the same in both: expand the globs, deduce an output directory, parse the acronym and type-override formats, and print how many files came out. That belongs in one place, so a fix lands in both.
Index ¶
- func DeduceOutputDir(outputDir string, queryFiles []string) (string, error)
- func GenCmd(labels Labels, goSubCmd *ffcli.Command) *ffcli.Command
- func Main(root *ffcli.Command)
- func ParseAcronyms(acronyms []string) (map[string]string, error)
- func ParseGoTypes(goTypes []string) (map[string]string, error)
- func RootCmd(labels Labels, longHelp string, subcommands ...*ffcli.Command) *ffcli.Command
- func VersionCmd(labels Labels, version, commit string) *ffcli.Command
- type GenFlags
- type Labels
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeduceOutputDir ¶
DeduceOutputDir returns outputDir if set, and otherwise the directory the query files live in. Query files spread across directories have no single answer, so that's an error rather than a guess.
func ParseAcronyms ¶
ParseAcronyms reads the --acronym flag, which takes either a bare word to upper-case ("api") or an explicit mapping ("apis=APIs").
func ParseGoTypes ¶
ParseGoTypes reads the --go-type flag, whose format is <dbType>=<goType>.
It splits on the last "=" rather than insisting on the only one, because a database type can contain "=" and a ClickHouse enum routinely does: it spells its labels in the type, as Enum8('MOC' = 1, 'GPRS' = 7), and that is exactly the type most worth overriding. A Go type reference cannot contain "=", so the last one is always the separator.
Types ¶
type GenFlags ¶
type GenFlags struct {
// contains filtered or unexported fields
}
GenFlags are the flags common to both gen commands.
func RegisterGenFlags ¶
RegisterGenFlags declares the shared gen flags on fset. The connection flag is not among them: each binary names it after its own database.
func (*GenFlags) GenerateGo ¶
GenerateGo resolves the flags and generates Go code for the queries they name, reporting how many files came out.
The whole body lives here rather than in each binary's Exec because the two differ only in the dialect and where the connection string comes from — leaving them to build the GenerateOptions themselves is how a newly added option gets wired into one binary and not the other.
type Labels ¶
type Labels struct {
Cmd string // "pggen" or "chgen"
DB string // "Postgres" or "ClickHouse"
SchemaHelp string // help for --schema-glob
GoTypeHelp string // help for --go-type
}
Labels are the words that differ between the two binaries: the command name, the database it talks to, and the help text for the flags whose wording is database-specific.