https://github.com/thrawn01/argsini
Parse INI config files for use with args parser
https://github.com/thrawn01/argsini
args cli golang ini
Last synced: about 1 year ago
JSON representation
Parse INI config files for use with args parser
- Host: GitHub
- URL: https://github.com/thrawn01/argsini
- Owner: thrawn01
- Created: 2017-06-09T22:51:39.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-10T00:03:58.000Z (almost 9 years ago)
- Last Synced: 2025-01-05T06:42:15.081Z (over 1 year ago)
- Topics: args, cli, golang, ini
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://coveralls.io/github/thrawn01/args-etcd)
[](https://travis-ci.org/thrawn01/args-etcd)
## Introduction
This repo provides an ini key=value storage backend for use with
[args](http://github.com/thrawn01/args)
## Installation
```
$ go get github.com/thrawn01/argsini
```
## Usage
```go
import (
"github.com/thrawn01/args"
"github.com/thrawn01/argsini"
)
parser := args.NewParser()
parser.AddOption("listen-address").Help("Specify local address to listen on")
parser.AddOption("config").Short("c").Required().Default("/etc/app/config.ini").
Help("Specify configuration file")
parser.AddOption("cache-size").IsInt().Default(150).
Help("Specify the size of the cache in entries")
// Parse the command line args
opt := parser.ParseOrExit(nil)
// Create a new backend object
backend := argsini.NewFromFile(opt.String("config"), "")
// Load the config file specified on the command line
opts, err := parser.FromBackend()
if err != nil {
fmt.Printf("config error - %s\n", err.Error())
}
// Print out the loaded config items
fmt.Printf("listen-address: %s\n", opts.String("listen"))
fmt.Printf("cache-size: %d\n", opts.Int("listen"))
// Watch ini file for any configuration changes
cancelWatch := parser.Watch(backend, func(event *args.ChangeEvent, err error) {
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Printf("Changed Event - %+v\n", event)
// This takes a ChangeEvent and update the opts with the latest changes
parser.Apply(opts.FromChangeEvent(event))
})
```