mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-29 13:49:28 +08:00

* Use per-service URL in SDK Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com> * Fix CLI Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com> * Fix CLI messaging Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com> * Fix message tests Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com> * Simplify Bootstrap Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com> * Update API doc and responses Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com> * fix failing certs, bootstrap tests Signed-off-by: mteodor <mirko.teodorovic@gmail.com> * fix failing certs, bootstrap tests Signed-off-by: mteodor <mirko.teodorovic@gmail.com> * Fix tests and rename to auth service Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com> * Clean the code Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com> * Remove unnecessary Repository logs Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Always return error in case of repo failure Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Cleanup SDK and CLI Update tests, remove linter warnings, remove dead code. Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Clean the code Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com> * Undo Bootstrap changes Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com> * Fix tests Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com> * Fix linter Signed-off-by: Drasko Draskovic <drasko.draskovic@gmail.com> Co-authored-by: mteodor <mirko.teodorovic@gmail.com> Co-authored-by: dusanb94 <dusan.borovcanin@mainflux.com>
79 lines
1.5 KiB
Go
79 lines
1.5 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/mainflux/mainflux/pkg/errors"
|
|
"github.com/pelletier/go-toml"
|
|
)
|
|
|
|
type Config struct {
|
|
Offset uint `toml:"offset"`
|
|
Limit uint `toml:"limit"`
|
|
Name string `toml:"name"`
|
|
RawOutput bool `toml:"raw_output"`
|
|
}
|
|
|
|
// save - store config in a file
|
|
func save(c Config, file string) error {
|
|
b, err := toml.Marshal(c)
|
|
if err != nil {
|
|
return errors.New(fmt.Sprintf("failed to read config file: %s", err))
|
|
}
|
|
if err := ioutil.WriteFile(file, b, 0644); err != nil {
|
|
return errors.New(fmt.Sprintf("failed to write config TOML: %s", err))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// read - retrieve config from a file
|
|
func read(file string) (Config, error) {
|
|
data, err := ioutil.ReadFile(file)
|
|
c := Config{}
|
|
if err != nil {
|
|
return c, errors.New(fmt.Sprintf("failed to read config file: %s", err))
|
|
}
|
|
|
|
if err := toml.Unmarshal(data, &c); err != nil {
|
|
return Config{}, errors.New(fmt.Sprintf("failed to unmarshal config TOML: %s", err))
|
|
}
|
|
return c, nil
|
|
}
|
|
|
|
func ParseConfig() {
|
|
if ConfigPath == "" {
|
|
// No config file
|
|
return
|
|
}
|
|
|
|
if _, err := os.Stat(ConfigPath); os.IsNotExist(err) {
|
|
errConfigNotFound := errors.Wrap(errors.New("config file was not found"), err)
|
|
logError(errConfigNotFound)
|
|
return
|
|
}
|
|
|
|
config, err := read(ConfigPath)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
if config.Offset != 0 {
|
|
Offset = config.Offset
|
|
}
|
|
|
|
if config.Limit != 0 {
|
|
Limit = config.Limit
|
|
}
|
|
|
|
if config.Name != "" {
|
|
Name = config.Name
|
|
}
|
|
|
|
if config.RawOutput {
|
|
RawOutput = config.RawOutput
|
|
}
|
|
}
|