switched to cmd line arguments for the config path

This commit is contained in:
sqshq 2019-02-12 20:46:18 -05:00
parent df5cee1d39
commit aa24aa4bd9
2 changed files with 11 additions and 3 deletions

View File

@ -1,12 +1,14 @@
package config
import (
"fmt"
"github.com/sqshq/sampler/console"
"github.com/sqshq/sampler/data"
. "github.com/sqshq/sampler/widgets"
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
"os"
)
type Config struct {
@ -23,9 +25,14 @@ type RunChartConfig struct {
Precision int `yaml:"decimal-places"`
}
func Load(location string) *Config {
func Load(args []string) *Config {
cfg := readFile(location)
if len(args) < 2 {
fmt.Fprintf(os.Stderr, "Please specify config file location. See www.github.com/sqshq/sampler for the reference\n")
os.Exit(0)
}
cfg := readFile(args[1])
cfg.validate()
cfg.setDefaultValues()
cfg.setDefaultColors()

View File

@ -7,12 +7,13 @@ import (
"github.com/sqshq/sampler/event"
"github.com/sqshq/sampler/widgets"
ui "github.com/sqshq/termui"
"os"
"time"
)
func main() {
cfg := config.Load("/Users/sqshq/Go/src/github.com/sqshq/sampler/config.yml")
cfg := config.Load(os.Args)
csl := console.Console{}
csl.Init()
defer csl.Close()