Clever/configure

Name: configure

Owner: Clever

Description: Seamlessly configure applications with either flags or JSON

Created: 2016-01-12 19:40:21.0

Updated: 2018-05-24 00:00:13.0

Pushed: 2018-05-24 00:00:12.0

Homepage:

Size: 21

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

configure

Easily fill in a configuration struct with either flag arguments or a JSON blob argument.

Usage

Given a simple program that uses two arguments, district_id and collection:

config struct {
DistrictID string `config:"district_id,required"`
Collection string `config:"collection"`


 main() {
if err := configure.Configure(&config); err != nil {
    log.Fatalf("err: %#v", err)
}
log.Printf("config: %#v", config)

// go use arguments to do something

It can be invoked two styles:

ample -h
e of ./example:
ollection string
  generated field
istrict_id string
  generated field

ample -district_id="abc123"
nfig: {DistrictID:abc123 Collection:}

ample '{"district_id":"abc123","collection":"schools"}'
nfig: {DistrictID:abc123 Collection:schools}

ample -district_id="abc123" -collection="schools"
nfig: {DistrictID:abc123 Collection:schools}

ils when not provided with the required district_id argument
ample -collection=schools
r: Missing required fields: [district_id]

ample '{"collection":"schools"}'
r: Missing required fields: [district_id]
Defining defaults

You can also define defaults by passing a pre-populated struct:

 main() {
config := struct {
    DistrictID string `config:"district_id,required"`
    Collection string `config:"collection"`
}{
    Collection: "default-collection",
}

if err := configure.Configure(&config); err != nil {
    log.Fatalf("err: %#v", err)
}
log.Printf("config: %#v\n", config)

// go use arguments to do something


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.