Documentation
¶
Overview ¶
Package cli provides shared configuration and utilities for the melange CLI.
Index ¶
Constants ¶
const ( ExitSuccess = 0 ExitGeneral = 1 ExitConfig = 2 ExitSchemaParse = 3 ExitDBConnect = 4 )
Exit codes per spec.
Variables ¶
This section is empty.
Functions ¶
func ExitWithError ¶
func ExitWithError(err error)
ExitWithError prints the error and exits with the appropriate code.
Types ¶
type ClientConfig ¶
type ClientConfig struct {
Runtime string `mapstructure:"runtime"`
Schema string `mapstructure:"schema"`
Output string `mapstructure:"output"`
Package string `mapstructure:"package"`
Filter string `mapstructure:"filter"`
IDType string `mapstructure:"id_type"`
}
ClientConfig holds client code generation settings.
type Config ¶
type Config struct {
// Schema is the path to the OpenFGA schema file (e.g., "schemas/schema.fga")
Schema string `mapstructure:"schema"`
// Database configuration
Database DatabaseConfig `mapstructure:"database"`
// Per-command configuration
Generate GenerateConfig `mapstructure:"generate"`
Migrate MigrateConfig `mapstructure:"migrate"`
Doctor DoctorConfig `mapstructure:"doctor"`
}
Config represents the melange configuration from melange.yaml.
func LoadConfig ¶
LoadConfig discovers and loads configuration with proper precedence: flags > env > config file > defaults.
Returns the loaded config, the path to the config file (empty if none found), and any error encountered.
func (*Config) DSN ¶
DSN returns the database connection string. If database.url is set, it's returned directly. Otherwise, builds a DSN from discrete fields.
func (*Config) ResolvedSchema ¶
ResolvedSchema returns the effective schema path, with generate.client.schema taking precedence over top-level schema (for generate command).
type DatabaseConfig ¶
type DatabaseConfig struct {
URL string `mapstructure:"url"`
Host string `mapstructure:"host"`
Port int `mapstructure:"port"`
Name string `mapstructure:"name"`
User string `mapstructure:"user"`
Password string `mapstructure:"password"`
SSLMode string `mapstructure:"sslmode"`
}
DatabaseConfig holds database connection settings.
type DoctorConfig ¶
type DoctorConfig struct {
Verbose bool `mapstructure:"verbose"`
}
DoctorConfig holds doctor command settings.
type ExitError ¶
ExitError wraps an error with an exit code.
func ConfigError ¶
ConfigError creates an ExitError with ExitConfig code.
func DBConnectError ¶
DBConnectError creates an ExitError with ExitDBConnect code.
func GeneralError ¶
GeneralError creates an ExitError with ExitGeneral code.
func SchemaParseError ¶
SchemaParseError creates an ExitError with ExitSchemaParse code.
type GenerateConfig ¶
type GenerateConfig struct {
Client ClientConfig `mapstructure:"client"`
}
GenerateConfig holds code generation settings.
type MigrateConfig ¶
type MigrateConfig struct {
DryRun bool `mapstructure:"dry_run"`
Force bool `mapstructure:"force"`
}
MigrateConfig holds migration settings.