cmd

package
v3.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: MIT Imports: 12 Imported by: 7

README

Command package

The Flamingo command package provides the Flamingo root command and allows to add additional commands under the Flamingo root command. It is based on the popular spf13/cobra package.

How to add new commands for the root command

Register your own commands via Dingo multibindings to *cobra.Command inside your Flamingo module.go file:

E.g.:

func (m *Module) Configure(injector *dingo.Injector) {
	injector.BindMulti(new(cobra.Command)).ToInstance(myCommand())
}

func myCommand() *cobra.Command {
	cmd := &cobra.Command{
		Use:   "myCommand",
		Short: "myCommand short desc",
		Run: func(cmd *cobra.Command, args []string) {
      doSomething()
		},
	}
	return cmd
}

Or, if you need Dingo to inject some configurations or other useful stuff then use a Dingo provider function to bind your command:

// Configure DI
func (m *Module) Configure(injector *dingo.Injector) {
	injector.BindMulti(new(cobra.Command)).ToProvider(MyCommand)
}

// MyCommand gets called by Dingo and all arguments are resolved and injected
func MyCommand(router *Router, area *config.Area) *cobra.Command {
  ... 
}

If your module is part of a Flamingo project, then you can call the command simply with:

go run main.go myCommand
About the Flamingo root command

The Flamingo root command is a *cobra.Command command annotated with flamingo.

It is normally used by the default bootstrap of Flamingo (see flamingo/app.go)

This is why the default output of a plain Flamingo project (using the default app bootstrap) looks like this:

$ go run main.go

Flamingo main

Usage:
  main [command]

Available Commands:
  config      Config dump
  help        Help about any command
  serve       Default serve command - starts on Port 3322

Flags:
  -h, --help   help for main

Use "main [command] --help" for more information about a command.

Adding persistent flags to the root command

You can add persistent flags to Flamingo's root command by multi-binding a FlagSet to *pflag.FlagSet:

// Configure DI
func (m *Module) Configure(injector *dingo.Injector) {
	injector.BindMulti((*pflag.FlagSet)(nil)).ToInstance(someFlagSet)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(injector *dingo.Injector) error

Run the root command

Types

type Module

type Module struct{}

Module for DI

func (*Module) Configure

func (m *Module) Configure(injector *dingo.Injector)

Configure DI

func (*Module) CueConfig added in v3.1.0

func (*Module) CueConfig() string

CueConfig specifies the command name

func (*Module) FlamingoLegacyConfigAlias added in v3.1.0

func (*Module) FlamingoLegacyConfigAlias() map[string]string

FlamingoLegacyConfigAlias maps legacy config to new

Jump to

Keyboard shortcuts

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