Documentation
¶
Overview ¶
Package cli provides shared configuration and utilities for the melange CLI.
Index ¶
- Constants
- func ConfigSearchPaths(dir string) []string
- func ExitWithError(err error)
- func TrimPatterns(patterns []string) []string
- type ClientConfig
- type Config
- type DatabaseConfig
- type DoctorConfig
- type EnvironmentConfig
- type ExitError
- type GenerateConfig
- type MigrateConfig
- type MigrationGenConfig
- type SQLConfig
- type SQLFunctionsConfig
- type SQLRelationsConfig
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 ConfigSearchPaths ¶ added in v0.11.0
ConfigSearchPaths returns the paths findConfigFile would try, in order, when run from dir: dir and then each parent up to the repository root, at most maxWalkDepth levels. dir and the results are slash-separated paths relative to the repository root ("" for the root itself), so they can name files at a git ref.
func ExitWithError ¶
func ExitWithError(err error)
ExitWithError prints the error and exits with the appropriate code.
func TrimPatterns ¶ added in v0.11.0
TrimPatterns returns patterns with surrounding whitespace removed, so a comma-separated environment variable may put spaces after the commas. Whitespace inside a pattern is still rejected by validation.
Types ¶
type ClientConfig ¶
type ClientConfig struct {
Runtime string `mapstructure:"runtime"`
Output string `mapstructure:"output"`
Package string `mapstructure:"package"`
// Relations selects the relations that get constants. Without an
// include it starts from sql.relations, so the client names what
// migrate exposes, and its excludes only narrow that.
Relations SQLRelationsConfig `mapstructure:"relations"`
// Filter is a relation name prefix applied after Relations. Deprecated
// in favor of relations.include (for example "can_*").
Filter string `mapstructure:"filter"`
IDType string `mapstructure:"id_type"`
}
ClientConfig holds client code generation settings.
func (ClientConfig) RelationPatterns ¶ added in v0.11.0
func (c ClientConfig) RelationPatterns(sqlRelations SQLRelationsConfig) compiler.RelationPatterns
RelationPatterns returns the client's relation selector. With its own include patterns it is the client's include and exclude alone. Without them it is sqlRelations, narrowed by the client's exclude patterns, so an exclude never names a relation migrate does not expose.
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"`
// SQL selects the generated SQL API (the exposure). It describes the
// schema, not a connection, so environments cannot override it.
SQL SQLConfig `mapstructure:"sql"`
// 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 ParseConfig ¶ added in v0.11.0
ParseConfig loads configuration from YAML content instead of a file, with the same defaults, environment variables and validation as LoadConfig. It reads a config file as it was at another revision.
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"`
// SkipClient skips the Generated Client checks, and StrictClient
// reports a client name the database does not answer for as a failure
// instead of a warning.
SkipClient bool `mapstructure:"skip_client"`
StrictClient bool `mapstructure:"strict_client"`
}
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.
type SQLConfig ¶ added in v0.11.0
type SQLConfig struct {
Relations SQLRelationsConfig `mapstructure:"relations"`
Functions SQLFunctionsConfig `mapstructure:"functions"`
}
SQLConfig is the sql section: which relations the public SQL API answers for and which function families are generated. Check functions are always generated. The section is declarative: migrate applies exactly what it resolves to, so removing it restores the default API.
type SQLFunctionsConfig ¶ added in v0.11.0
type SQLFunctionsConfig struct {
ListObjects bool `mapstructure:"list_objects"`
ListSubjects bool `mapstructure:"list_subjects"`
Accessible bool `mapstructure:"accessible"`
ParentKey bool `mapstructure:"parent_key"`
Expand bool `mapstructure:"expand"`
Explain bool `mapstructure:"explain"`
}
SQLFunctionsConfig enables the optional function families.
type SQLRelationsConfig ¶ added in v0.11.0
type SQLRelationsConfig struct {
Include []string `mapstructure:"include"`
Exclude []string `mapstructure:"exclude"`
}
SQLRelationsConfig holds the relation patterns: "relation" or "type#relation", with '*' and '?' globs within a part. A relation is exposed when it matches an include pattern (every relation when include is empty) and no exclude pattern.
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. |