cli

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeduceOutputDir

func DeduceOutputDir(outputDir string, queryFiles []string) (string, error)

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 GenCmd

func GenCmd(labels Labels, goSubCmd *ffcli.Command) *ffcli.Command

GenCmd builds the "gen" command, which only dispatches to a language.

func Main

func Main(root *ffcli.Command)

Main runs root and turns an error into a message and a non-zero exit.

func ParseAcronyms

func ParseAcronyms(acronyms []string) (map[string]string, error)

ParseAcronyms reads the --acronym flag, which takes either a bare word to upper-case ("api") or an explicit mapping ("apis=APIs").

func ParseGoTypes

func ParseGoTypes(goTypes []string) (map[string]string, error)

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.

func RootCmd

func RootCmd(labels Labels, longHelp string, subcommands ...*ffcli.Command) *ffcli.Command

RootCmd builds the top-level command, which only prints usage.

func VersionCmd

func VersionCmd(labels Labels, version, commit string) *ffcli.Command

VersionCmd builds the "version" command.

Types

type GenFlags

type GenFlags struct {
	// contains filtered or unexported fields
}

GenFlags are the flags common to both gen commands.

func RegisterGenFlags

func RegisterGenFlags(fset *flag.FlagSet, labels Labels) *GenFlags

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

func (f *GenFlags) GenerateGo(dialect pggen.Dialect, connString string) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL