Thanks to visit codestin.com
Credit goes to github.com

Skip to content

thrawn01/argsini

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Coverage Status Build Status

Introduction

This repo provides an ini key=value storage backend for use with args

Installation

$ go get github.com/thrawn01/argsini

Usage

    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))
    })

About

Parse INI config files for use with args parser

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published