mode

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2025 License: GPL-3.0 Imports: 4 Imported by: 19

Documentation

Index

Constants

View Source
const (
	// FlagName is the name of the mode flag.
	FlagName = "mode"

	// FlagUsage is the usage of the mode flag. It describes allowed values and the default mode.
	FlagUsage = "Specify mode. Allowed values are: %s. Default is the %s mode."
)

Variables

View Source
var (
	// Dev is the development mode.
	Dev Mode = "dev"

	// Prod is the production mode.
	Prod Mode = "prod"

	// Debug is the debug mode.
	Debug Mode = "debug"

	// Migrate is the migration mode.
	Migrate Mode = "migrate"

	// Setup is the setup mode.
	Setup Mode = "setup"

	// DefaultMode is the default mode (development).
	DefaultMode = Dev

	// AllowedModes is the list of allowed modes.
	AllowedModes = []string{
		string(Dev),
		string(Prod),
		string(Debug),
		string(Migrate),
		string(Setup),
	}

	// ModeFlag is the environment mode flag instance.
	ModeFlag = NewFlag(
		string(DefaultMode),
		nil,
		AllowedModes,
		FlagName,
		fmt.Sprintf(
			FlagUsage,
			strings.Join(AllowedModes, ", "),
			string(Dev),
		),
	)
)
View Source
var (
	ErrNilModeFlag = errors.New("mode flag cannot be nil")
)

Functions

This section is empty.

Types

type Flag

type Flag struct {
	goflags.Flag
}

Flag is a custom flag type for mode, embedding goflags.Flag.

func NewFlag

func NewFlag(
	defaultValue string,
	value *string,
	allowed []string,
	name string,
	usage string,
) *Flag

NewFlag creates a new Flag with allowed values.

Parameters:

defaultValue - the default value for the flag.
value - pointer to a string to store the flag value (can be nil).
allowed - slice of allowed string values.
name - the flag name.
usage - the usage description for the flag.

Returns:

A pointer to the created Flag.

func (*Flag) Default added in v0.3.4

func (f *Flag) Default() string

Default returns the default value of the flag.

Returns:

The default value.

func (*Flag) IsDebug added in v0.2.0

func (f *Flag) IsDebug() bool

IsDebug returns true if the current mode is debug.

Returns:

True if debug mode, false otherwise.

func (*Flag) IsDev

func (f *Flag) IsDev() bool

IsDev returns true if the current mode is development.

Returns:

True if development mode, false otherwise.

func (*Flag) IsMigrate added in v0.3.3

func (f *Flag) IsMigrate() bool

IsMigrate returns true if the current mode is migration.

Returns:

True if migration mode, false otherwise.

func (*Flag) IsProd

func (f *Flag) IsProd() bool

IsProd returns true if the current mode is production.

Returns:

True if production mode, false otherwise.

func (*Flag) IsSetup added in v0.3.5

func (f *Flag) IsSetup() bool

IsSetup returns true if the current mode is setup.

Returns:

True if setup mode, false otherwise.

type Mode

type Mode string

Mode represents the environment mode as a string.

Jump to

Keyboard shortcuts

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