Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Init input source from toml, but got empty field #755

Closed
asaarashi opened this issue Jun 13, 2018 · 5 comments
Closed

Init input source from toml, but got empty field #755

asaarashi opened this issue Jun 13, 2018 · 5 comments

Comments

@asaarashi
Copy link

asaarashi commented Jun 13, 2018

I have

package main

import (
    "os"
    "gopkg.in/urfave/cli.v1"
    "github.com/urfave/cli/altsrc"
    "log"
)

func main() {
    app := cli.NewApp()
    app.Name = "pusher"
    app.Description = "tbuploather pusher"

    flags := []cli.Flag{
        cli.BoolFlag{Name: "debug, d", Usage: "debug"},
        altsrc.NewStringFlag(cli.StringFlag{Name: "dsn, D", Usage: "MySQL DSN"}),
        altsrc.NewStringSliceFlag(cli.StringSliceFlag{Name: "broker-list, b", Usage: "Kafka brokers"}),
        cli.StringFlag{Name: "log-path, l", Value: "/var/log/tbuploather/pusher.log", Usage: "File log path"},
        cli.StringFlag{Name: "config-file, c", Value: "pusher.toml", Usage: "Config file path"},
    }
    app.Action = DefaultAction
    app.Before = altsrc.InitInputSourceWithContext(flags, altsrc.NewTomlSourceFromFlagFunc("config-file"))
    app.Flags = flags

    err := app.Run(os.Args)
    if err != nil {
        log.Println(err)
    }
}

but

ctx.String("dsn")

is always empty.

This is my toml file

debug = false
broker-list = ["192.168.30.169:9092,33333"]
log-path = "/var/log/tbuploather/pusher.log"
dsn = "root:asdf@tcp(192.168.30.169:3306)/tbuploather"

what's the possible reason? Thx!

@johnwyles
Copy link

I would try switching to urfave/cli.v2 and also removing the aliases for your cli arguments: e.g. dsn, D => dsn to start

@coilysiren
Copy link
Member

Hiya! There's a known issue with the current implementation of the CLI, where altsrc is generally clunky and poorly documented. My current idea is that I'm going to move all of the altsrc functionality into the main package in some way, and that's how all of the "altsrc is weird and different???" issues people are having will get resolved. I'm tracking that work here => #833

@prestonvanloon
Copy link

Does altsrc work then? Having the same issues

@prestonvanloon
Copy link

This doesn't work with v2 either.

@coilysiren
Copy link
Member

Many things with altsrc are known broken in v2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants