mkideal / cli

CLI - A package for building command line app with go
MIT License
730 stars 43 forks source link

Self in sub command #20

Closed suntong closed 8 years ago

suntong commented 8 years ago

Hiya,

Please take a look at 027s-subc.go

This is how I run it,

echo '{ "Dir": "DDD", "Suffix": "sss", "Out": "oooo" }' > build.json

$ go run 027s-subc.go build aaa
[build]:
  &{Helper:{Help:false} Host: Port:80}
  &{Self:0xc8200184c0 Dir:./ Suffix:.go,.c,.s Out:}
  [aaa]

The Self in sub command is supposed to pick up values defined in the build.json file, and I surely remember it did it before, but now it seems not doing it.

mkideal commented 8 years ago

I'm sorry. I made a mistake when fix Reader and Writer, See commit 7bfc6df. And Self should be the last field of strcutre:

type buildT struct {
    Dir    string  `cli:"dir" usage:"source code root dir" dft:"./"`
    Suffix string  `cli:"suffix" usage:"source file suffix" dft:".go,.c,.s"`
    Out    string  `cli:"o,out" usage:"output filename"`
    Self   *buildT `cli:"c,config" usage:"config file" json:"-" parser:"jsonfile" dft:"build.json"`
}

otherwise, the values(read from json file) will be covered by the dft values

suntong commented 8 years ago

Bingo. Thanks,