Skip to content
This repository has been archived by the owner on Apr 27, 2022. It is now read-only.

Commit

Permalink
Merge 53a7a6c into ad2c190
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Piegay committed May 12, 2016
2 parents ad2c190 + 53a7a6c commit c0cf666
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
debug.test
coverage.out
coverage.out
example*
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Containous SAS, Emile Vauge, emile@vauge.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
117 changes: 116 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,116 @@
# staert
# Stært
[![Travis branch](https://img.shields.io/travis/containous/staert/master.svg)](https://travis-ci.org/containous/staert)
[![Coverage Status](https://coveralls.io/repos/github/containous/staert/badge.svg?branch=master)](https://coveralls.io/github/containous/staert?branch=master)
[![license](https://img.shields.io/github/license/containous/staert.svg)](https://github.com/containous/staert/blob/master/LICENSE.md)

Stært is a Go library for loading and merging a program configuration structure from many sources.

## Overview
Stært born in order to merge two sources of Configuration ([Flæg](https://github.com/containous/flaeg), [Toml](http://github.com/BurntSushi/toml))

## Features
- Load your Configuration structure from many sources
- Keep your Configuration structure values unchanged if no overwriting (support defaults values)
- Two native sources :
- [Flæg](https://github.com/containous/flaeg)
- [Toml](http://github.com/BurntSushi/toml)
- An Interface to add your own sources
- Handle pointers field :
- You can give a structure of default values for pointers
- Same comportment as [Flæg](https://github.com/containous/flaeg)
- Stært is Command oriented
- It use `flaeg.Command`
- Same comportment as [Flæg](https://github.com/containous/flaeg) commands

## Getting Started
### The configuration
It works on your own Configuration structure, like this one :
```go
import (
"github.com/containous/flaeg"
"github.com/containous/staert"
)

//Configuration is a struct which contains all differents type to field
type Configuration struct {
IntField int `description:"An integer field"`
StringField string `description:"A string field"`
PointerField *PointerSubConfiguration `description:"A pointer field"`
}

//PointerSubConfiguration is a SubStructure Configuration
type PointerSubConfiguration struct {
BoolField `description:"A boolean field"`
FloatField `description:"A float field"`
}
```

Let's initialize it:
```go
//Init with default value
config := &Configuration{
IntField: 1,
StringField: "init",
PointerField: &PointerSubConfiguration{
FloatField: 1.1,
},
}
//Set default pointers value
defaultPointersConfig := &Configuration{
PointerField: &PointerSubConfiguration{
BoolField: true,
FloatField: 99.99,
},
}
```

### The command
Stært uses `flaeg.Command` Structure, like this :
```go
//Creat Command
command:=&flaeg.Command{
Name:"example",
Description:"This is an example of description",
Config:config,
DefaultPointersConfig:defaultPointersConfig,
Run: func() error {
fmt.Printf("Run example with the config :\n%+v\n",config)
return nil
}
}
```

### Use stært with sources
Init Stært
```go
s:=staert.NewStaert(command)
```
Init TOML source
```go
toml:=staert.NewTomlSource("example", []string{"./toml/", "/any/other/path"})
```
Init Flæg source
```go
f:=flaeg.New(command, os.Args[1])
```
### Add sources
Add TOML and flæg sources
```go
s.AddSource(toml)
s.AddSource(f)
```

### Now run
JUST RUN
```go
if err := s.Run(); err != nil {
//OUPS
}
```

## Contributing
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

0 comments on commit c0cf666

Please sign in to comment.