from the compilation error, it would seem kingpin.Flag...ExistingFile()
returns a *string, not a string.
so these lines:
 fmt.Printf("%v, %s, %T\n", config, config, config)
 cfg, err := ini.Load(config)
should be replaced with:
 fmt.Printf("%v, %s, %T\n", *config, *config, *config)
 cfg, err := ini.Load(*config)

hth,
-s

On Tue, Feb 26, 2019 at 10:46 AM Natxo Asenjo <natxo.ase...@gmail.com>
wrote:

> hi,
>
> I am writing a script that accepts arguments and flags (using kingpin) but
> am failing miserably so far. One of the arguments is a file name, which
> should be then loaded by an ini library (file is in ini format).
>
> If I hard code the file name in the script, it works, but
>
> Code:
>
> =====================start ====================================
> package main
>
> import (
>     "fmt"
>     "gopkg.in/alecthomas/kingpin.v2"
>     "gopkg.in/ini.v1"
>     "os"
> )
>
> var (
>     config              = kingpin.Flag("config", "configuration
> file").Short('c').Required().ExistingFile()
>     url, api, user, pwd = parse_config()
> )
>
> func init() {
>     kingpin.Parse()
> }
>
> func main() {
>     fmt.Println("yay")
> }
>
> func parse_config() (string, string, string, string) {
>     //cfg, err := ini.Load("api.conf")
>     fmt.Printf("%v, %s, %T\n", config, config, config)
>     cfg, err := ini.Load(config)
>     if err != nil {
>         fmt.Println(err)
>         os.Exit(1)
>     }
>
>     url := cfg.Section("").Key("url").String()
>     api := cfg.Section("").Key("api").String()
>     user := cfg.Section("").Key("user").String()
>     pwd := cfg.Section("").Key("password").String()
>
>     return url, api, user, pwd
> }
>
> =====================end====================================
> and when running it:
>
> $ go run yetanother.go --config api.conf
> 0xc0000547e0, %!s(*string=0xc0000547e0), *string
> error parsing data source: unknown type '%!s(*string=0xc00008ceb0)'
> exit status 1
>
> This must be pretty basic, but I'm stuck :(
>
> Any tips welcome.
>
> Thanks in advance.
>
> --
> regards,
> Natxo
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to