microcli

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

README

microcli Source

The microcli source reads config from parsed flags via a cli.Context.

Format

We expect the use of the micro/cli package. Upper case flags will be lower cased. Dashes will be used as delimiters for nesting.

Example
micro.Flags([]cli.Flag{
    cli.StringFlag{
        Name: "database-address",
        Value: "127.0.0.1",
        Usage: "the db address",
    },
    cli.IntFlag{
        Name: "database-port",
        Value: 3306,
        Usage: "the db port",
    },
})

Becomes

{
    "database": {
        "address": "127.0.0.1",
        "port": 3306
    }
}

New and Load Source

Because a cli.Context is needed to retrieve the flags and their values, it is recommended to build your source from within a cli.Action.


func main() {
    // New Service
    service := micro.NewService(
        micro.Name("example"),
        micro.Flags([]cli.Flag{
            cli.StringFlag{
                Name: "database-address",
                Value: "127.0.0.1",
                Usage: "the db address",
            },
        }),
    )

    var clisrc source.Source

    service.Init(
        micro.Action(func(c *cli.Context) {
            clisrc = microcli.NewSource(c)
            // Alternatively, just setup your config right here
        }),
    )
    
    // ... Load and use that source ...
    conf := config.NewConfig()
    conf.Load(clisrc)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSource

func NewSource(ctx *cli.Context, opts ...source.Option) source.Source

NewSource returns a config source for integrating parsed flags from a micro/cli.Context. Hyphens are delimiters for nesting, and all keys are lowercased.

Example:

cli.StringFlag{Name: "db-host"},

{
    "database": {
        "host": "localhost"
    }
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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