cli

package
v0.20.14 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2021 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

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

cli Source

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

Format

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

Example
vine.Flags(
    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 := vine.NewService(
        vine.Name("example"),
        vine.Flags(
            cli.StringFlag{
                Name: "database-address",
                Value: "127.0.0.1",
                Usage: "the db address",
            },
        ),
    )

    var clisrc source.Source

    service.Init(
        vine.Action(func(c *cli.Context) {
            clisrc = cli.NewSource(
                cli.Context(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 Context

func Context(c *cli.Context) source.Option

Context sets the cli context

func NewSource

func NewSource(opts ...source.Option) source.Source

NewSource returns a config source for integrating parsed flags from a vine/cli.Context. Hyphens are delimiters for nesting, and all keys are lowercased. The assumption is that command line flags have already been parsed.

Example:

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

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

func WithContext

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

WithContext returns a new source with the context specified. The assumption is that Context is retrieved within an app.Action function.

Types

This section is empty.

Jump to

Keyboard shortcuts

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