commands

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: MIT Imports: 19 Imported by: 0 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

commands-go

Most used cli commands for services and applications

Documentation

Index

Constants

View Source
const (
	CommandContextCfgKey        CommandContextKey = "cfg"
	CommandContextCfgKeyDB                        = CommandContextCfgKey + ".db"
	CommandContextCfgKeyLog                       = CommandContextCfgKey + ".log"
	CommandContextCfgKeyAppInfo                   = CommandContextCfgKey + ".appInfo"
	CommandContextCfgKeyStage                     = CommandContextCfgKey + ".stage"
)
View Source
const (
	CommandContextObjectKey       CommandContextKey = "obj"
	CommandContextObjectKeySeeder                   = CommandContextObjectKey + ".seeder"
	CommandContextObjectKeyConfig                   = CommandContextObjectKey + ".config"
)
View Source
const (
	CmdFailureCode  = 1
	CmdErrStrFormat = "%s %s error: %w"
)

Variables

View Source
var (
	ErrNoMethodFound                  = errors.New("seed method is not exists")
	ErrSeedIsDisabled                 = errors.New("seed method is disabled in config")
	ErrSeedClassNameNotRegistered     = errors.New("seed class name not registered")
	ErrSeedClassIsNotValid            = errors.New("seed class name not valid")
	ErrSeedClassNotImplementInterface = errors.New("seed class name not implements commands.SeedInterface")
	ErrBadContextValue                = errors.New("context value is empty (not passed as pointer?) or don't implement interface")
)
View Source
var (
	SeedCmd = &cobra.Command{
		Use:       "seed",
		Short:     "Database seeding command",
		ValidArgs: []string{"run", "run-all", "list"},
		Args:      cobra.MinimumNArgs(1),
	}

	SeedRunAllCmd = &cobra.Command{
		Use:  "run-all",
		RunE: seedRunAll,
	}
	SeedRunCmd = &cobra.Command{
		Use:  "run",
		Args: cobra.MinimumNArgs(1),
		RunE: seedRun,
	}
)

SeedCmd is a database seeding wrapper command.

View Source
var MigrateCmd = &cobra.Command{
	Use:       "migrate",
	Short:     "Database migrations command",
	ValidArgs: []string{"up", "up-by-one", "up-to", "create", "down", "down-to", "fix", "redo", "reset", "status", "version"},
	Args:      cobra.MinimumNArgs(1),
	RunE:      migrate,
}

MigrateCmd is a github.com/pressly/goose database migrate wrapper command.

View Source
var VersionCmd = &cobra.Command{
	Use:   "version",
	Short: "Print the version number",
	RunE: func(cmd *cobra.Command, args []string) error {
		appInfo, ok := cmd.Context().Value(CommandContextCfgKeyAppInfo).(contracts.ApplicationInfoCfgInterface)
		if !ok {
			return fmt.Errorf("%w: app info config (cfg.appInfo)", ErrBadContextValue)
		}

		cmd.Println(appInfo.GetVersion())

		return nil
	},
}

Functions

func SeedMethodType

func SeedMethodType(seed SeedInterface) reflect.Type

SeedMethodType checks SeedInterface implementation and returns Seed object reflect.Type.

Types

type CommandContextKey

type CommandContextKey string

type SeedInterface

type SeedInterface interface {
	Enabled() bool
	Name() string
	Seed() error
	SetRepo(r interface{})
	SetCfg(c cfgstructs.SeedInfo)
}

type Seeder

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

func (Seeder) GetMethod

func (s Seeder) GetMethod(name string) (SeedInterface, error)

func (Seeder) GetMethods

func (s Seeder) GetMethods() map[string]SeedInterface

func (Seeder) SeedsList

func (s Seeder) SeedsList() []string

type SeederInterface

type SeederInterface interface {
	GetMethods() map[string]SeedInterface
	GetMethod(name string) (SeedInterface, error)
	SeedsList() []string
}

func NewSeeder

func NewSeeder(cfg cfgstructs.SeedingCfg, seeds map[string]reflect.Type, repo interface{}) (SeederInterface, error)

NewSeeder initiates new Seeder object.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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