core

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigPathDefault = ".schemadoc.yaml"
	ConfigPathEnv     = "SCHEMADOC_CONFIG"
)

Variables

This section is empty.

Functions

func ConfigPath

func ConfigPath(args []string) (string, error)

ConfigPath resolves and returns the config path. Lookup order:

  • Flag
  • Environment variable
  • Default path name

Types

type App

type App struct {
	Config *Config
	Logger *Logger
	Meta   *Meta
	IO     *ui.IOStreams
	UI     *ui.UserInterface
	// contains filtered or unexported fields
}

App contains global and/or singleton application data.

func AppForContext

func AppForContext(ctx context.Context) *App

AppForContext returns the app singleton stored in the given context.

func NewApp

func NewApp(version, commit, date, path string) (*App, error)

NewApp returns the default App singleton. It will be minimally initialized with metadata and config. Call `Init()` after flag parsing to complete initialization.

func NewTestApp

func NewTestApp() *App

NewTestApp returns the test App singleton. All properties will be configured for testing (mocks, stubs, etc).

func (*App) Close

func (a *App) Close() error

Close ensures all app resources have been closed.

func (*App) Context

func (a *App) Context() context.Context

Context returns the root context.Context for the app.

func (*App) Init

func (a *App) Init() error

Init initializes and configures the app. It must be called once flags have been parsed.

func (*App) InitForTest

func (a *App) InitForTest()

Init initializes and configures the app for unit testing.

type Config

type Config struct {
	ConfigPath string
	Color      bool   `yaml:"color" env:"SCHEMADOC_COLOR" default:"true"`
	Debug      bool   `yaml:"debug" env:"SCHEMADOC_DEBUG"`
	Prompt     bool   `yaml:"prompt" env:"SCHEMADOC_PROMPT" default:"true"`
	LogLevel   string `yaml:"log_level" env:"SCHEMADOC_LOG_LEVEL" default:"warn" validate:"oneof=debug info warn error fatal"` //nolint: lll
}

func NewConfigFromPath

func NewConfigFromPath(path string) (*Config, error)

NewConfigFromPath returns a new config for the file at path.

func NewTestConfig

func NewTestConfig() (*Config, error)

NewTestConfig returns a new Config for unit tests populated with default values.

type Logger

type Logger struct {
	*log.Logger
}

Logger is a simple wrapper around the charmbracelet/log package.

func NewLogger

func NewLogger(ios *ui.IOStreams, config *Config) *Logger

NewLogger returns a new Logger.

type Meta

type Meta struct {
	BuildCommit    string
	BuildTime      time.Time
	BuildGoVersion string
	BuildVersion   string
	BuildChecksum  string
	Version        string
	GOOS           string
	GOARCH         string
}

Meta contains application metadata (version, os, build info, etc).

func NewMeta

func NewMeta(version, commit, date string) *Meta

NewMeta returns a new Meta struct.

Jump to

Keyboard shortcuts

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