cli

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package cli

Gopoly generates custom unmarshaling functions for provided interface. It uses built-in go tooling to scan packages and look for implementing types as well as polymorphic fields.

By default, it will look for a .gopoly.yaml file as a main source of the configuration but configuration can be provided via command line. Due to complicated configuration inputs it's preferable to provide config via .gopoly.yaml file. If both are provided, inputs from command line overwrite inputs from config file.

Usage:

gopoly [flags]

The flags are:

-c
	Provide path to the config file. Default value is .gopoly.yaml
-p
	Scoped package where models are located.
-d
	Decoding strategy to be used when unmarshaling functions are generated.
	Can be either 'strict' or 'discriminator'
-o
	Output filename that will contain generated code. Please be mindful that if you provide
	a full or relative path, it will be ignored. Since unmarshaling functions need to be
	generated in the same package.
-m
	Marker method. Marker-method is a way 'mark' types that belong to a specific interface,
	basically serving as a metadata. Default value is Is{{.Name}}. And type will be taken from
	the interface
-t
	Types information.

Examples

Generate unmarshaling functions based on the default config file:

gopoly

Generate unmarshaling functions based on the custom named config file:

gopoly -c .gopoly-config.yaml

Generate unmarshaling based on command input only:

gopoly -p "github.com/username/example/models" \
	-o "out.gen.go" \
	-d "strict" \
	-m "IsRunner" \
	-t 'Runner subtypes=A,B'

Generate unmarshaling based on custom config file and command input :

gopoly -c .gopoly-config.yaml \
	-p "github.com/username/example/models" \
	-o "out.gen.go" \
	-d "strict" \
	-m "IsRunner" \
	-t 'Runner subtypes=A,B'

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MergedConfigProvider

func MergedConfigProvider() (*config.Config, error)

func PrintTraceAndExit

func PrintTraceAndExit(app *App)

Types

type App

type App struct {
	Logf           func(format string, args ...any)
	Ctx            context.Context
	RecoveryFunc   RecoveryFunc
	ConfigProvider func() (*config.Config, error)
}

func (*App) Execute

func (a *App) Execute(info *RunInfo)

func (*App) Exit

func (a *App) Exit(status int)

func (*App) RunInit

func (a *App) RunInit() error

type RecoveryFunc

type RecoveryFunc func(*App)

type RunInfo

type RunInfo struct {
	ModSum     string
	ModVersion string
}

func (*RunInfo) String

func (r *RunInfo) String() string

type TypesInput

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

func (*TypesInput) Set

func (t *TypesInput) Set(s string) error

func (*TypesInput) String

func (t *TypesInput) String() string

Jump to

Keyboard shortcuts

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