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 // ExitDatabaseAhead means migrate refused because a newer melange already // migrated the database. Startup scripts can treat it as success: the // newer functions keep the same SQL API. ExitDatabaseAhead = 5 )
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"`
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"`
// DefaultEnvironment names the environment applied when neither the --env
// flag nor MELANGE_ENV selects one. Empty means "use the base config".
DefaultEnvironment string `mapstructure:"default_environment"`
// Environments are named connection profiles. Each overlays the base
// configuration (see ForEnvironment); a field an environment leaves unset
// falls through to the base. Absent map ⇒ behavior identical to before
// environments existed.
Environments map[string]EnvironmentConfig `mapstructure:"environments"`
// contains filtered or unexported fields
}
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) EnvironmentSummary ¶ added in v0.9.3
EnvironmentSummary returns a redacted, human-readable connection target for the named environment (or the base config when name == ""). Unlike ForEnvironment it does not expand ${VAR} references — a listing should show what is configured, not whatever happens to be in the current shell — and it redacts any URL password. Returns an error only when name is a non-empty environment that is not defined.
func (*Config) ForEnvironment ¶ added in v0.9.3
ForEnvironment returns a copy of the config with the named environment overlaid and ${VAR} references expanded. An empty envName returns the base config (still with ${VAR} expansion applied, so the base database block may reference secrets too).
A non-empty envName that is not defined is an error (returned with a nil config). An unset ${VAR} reference is also an error — an unset secret must fail loud rather than silently resolve and retarget the command — but there the returned config is still populated best-effort (unset references expand to empty), so callers may use its non-connection fields (e.g. Schema) and honor an explicit --db while any DSN attempt fails loud.
func (*Config) HasEnvironment ¶ added in v0.9.3
HasEnvironment reports whether the named environment profile is defined.
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"`
Schema string `mapstructure:"schema"`
}
DatabaseConfig holds database connection settings.
type DoctorConfig ¶
type DoctorConfig struct {
Verbose bool `mapstructure:"verbose"`
SkipPerformance bool `mapstructure:"skip_performance"`
}
DoctorConfig holds doctor command settings.
type EnvironmentConfig ¶ added in v0.9.3
type EnvironmentConfig struct {
Database DatabaseConfig `mapstructure:"database"`
Schema string `mapstructure:"schema"`
}
EnvironmentConfig is a named connection profile overlaid onto the base Config by ForEnvironment. Typically only Database is set; Schema is available for the uncommon case of an environment that reads a different schema file.
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"`
Migration MigrationGenConfig `mapstructure:"migration"`
}
GenerateConfig holds code generation settings.
type MigrateConfig ¶
type MigrateConfig struct {
DryRun bool `mapstructure:"dry_run"`
Force bool `mapstructure:"force"`
}
MigrateConfig holds settings for `melange migrate` (builtin migration).
type MigrationGenConfig ¶ added in v0.9.0
type MigrationGenConfig struct {
Output string `mapstructure:"output"`
Name string `mapstructure:"name"`
Format string `mapstructure:"format"`
}
MigrationGenConfig holds settings for `melange generate migration`, which produces versioned SQL files for use with external migration frameworks. This is distinct from MigrateConfig, which controls `melange migrate` (the built-in apply-to-database workflow). Configuring both for the same database is discouraged; the migrate command warns when generate.migration.output is set.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package render formats melange.Trace values for terminal display.
|
Package render formats melange.Trace values for terminal display. |
|
Package style is the CLI's single terminal palette, expressed as lipgloss colors.
|
Package style is the CLI's single terminal palette, expressed as lipgloss colors. |