cmd

package
v3.0.0-alpha2 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2019 License: OSL-3.0 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 method which belongs to dingo.Module interface.
// Responsible for module configuration (dependency injection, setting up handlers etc)
func (m *Module) Configure(injector *dingo.Injector) {
	injector.BindMulti(new(cobra.Command)).ToProvider(MyCommand)
}



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 normaly used by the default bootstrap of flamingo (see flamingo/app.go)

This is why the default outpout of a plain flamingo project (using the default app bootstrap)

Looks something 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.

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) DefaultConfig

func (m *Module) DefaultConfig() config.Map

DefaultConfig specifies the command name

Jump to

Keyboard shortcuts

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