This commit is contained in:
parent
5609f59448
commit
761f8386e7
19
README.md
19
README.md
@ -13,7 +13,7 @@ go get gopkg.in/yaml.v3
|
||||
1. Install **config** library:
|
||||
|
||||
```sh
|
||||
go get github.com/eschao/config
|
||||
git@git.mousesoft.ru:ms/config.git
|
||||
```
|
||||
|
||||
## Usage
|
||||
@ -41,6 +41,7 @@ Like JSON, Yaml, **config** uses tags to define configurations:
|
||||
* int8, int16, int, int32, int64
|
||||
* uint8, uint16, uint, uint32, uint64
|
||||
* float32, float64
|
||||
* time.Duration
|
||||
* slice type. e.g: []string, []int ...
|
||||
|
||||
#### 2. Defines **default** values
|
||||
@ -294,6 +295,22 @@ Then, you can parse as below:
|
||||
// error handling
|
||||
}
|
||||
|
||||
cmd := config.NewCLI("")
|
||||
if err := cmd.Init(&dbConfig); err != nil {
|
||||
// error handling
|
||||
}
|
||||
|
||||
// capture cli flags
|
||||
args := cmd.Capture(os.Args)
|
||||
|
||||
// parse cli flags of application, urfave for example
|
||||
flagSet.Parse(args)
|
||||
|
||||
// parse captured cli flags of config
|
||||
if err := cmd.Parse(cmd.Args); err != nil {
|
||||
// error handling
|
||||
}
|
||||
|
||||
// parse configuration file from command line
|
||||
err := config.ParseConfig(&dbConfig, "c")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user