switched to cmd line arguments for the config path
This commit is contained in:
parent
df5cee1d39
commit
aa24aa4bd9
|
@ -1,12 +1,14 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/sqshq/sampler/console"
|
"github.com/sqshq/sampler/console"
|
||||||
"github.com/sqshq/sampler/data"
|
"github.com/sqshq/sampler/data"
|
||||||
. "github.com/sqshq/sampler/widgets"
|
. "github.com/sqshq/sampler/widgets"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
@ -23,9 +25,14 @@ type RunChartConfig struct {
|
||||||
Precision int `yaml:"decimal-places"`
|
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.validate()
|
||||||
cfg.setDefaultValues()
|
cfg.setDefaultValues()
|
||||||
cfg.setDefaultColors()
|
cfg.setDefaultColors()
|
||||||
|
|
3
main.go
3
main.go
|
@ -7,12 +7,13 @@ import (
|
||||||
"github.com/sqshq/sampler/event"
|
"github.com/sqshq/sampler/event"
|
||||||
"github.com/sqshq/sampler/widgets"
|
"github.com/sqshq/sampler/widgets"
|
||||||
ui "github.com/sqshq/termui"
|
ui "github.com/sqshq/termui"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
cfg := config.Load("/Users/sqshq/Go/src/github.com/sqshq/sampler/config.yml")
|
cfg := config.Load(os.Args)
|
||||||
csl := console.Console{}
|
csl := console.Console{}
|
||||||
csl.Init()
|
csl.Init()
|
||||||
defer csl.Close()
|
defer csl.Close()
|
||||||
|
|
Loading…
Reference in New Issue