Skip to content

Commit

Permalink
support custom config file from command line
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Andre Birkedal committed Nov 5, 2021
1 parent bf532b1 commit a7e48ab
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
11 changes: 10 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@ type Data struct {
OnlyMessages bool `yaml:"only_messages"`
}

func ParseCustom(filename string) Data {
return parseData(filename)
}

func Parse() Data {
filename, _ := getPaths()
return parseData(filename)
}

func parseData(filename string) Data {
var result Data
filename, configDir := getPaths()
configDir := filepath.Base(filename)

// Don't care if this fails
_ = os.MkdirAll(configDir, 0700)
Expand Down
26 changes: 24 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
"github.com/termoose/irccloud/config"
Expand All @@ -11,11 +12,21 @@ import (
)

func main() {
// Set this so we don't overwrite the default terminal
configFilename := flag.String("c", "", "path to config file")
flag.Parse()

// Set this, so we don't overwrite the default terminal
// background color
tview.Styles.PrimitiveBackgroundColor = tcell.ColorDefault

conf := config.Parse()
var conf config.Data

if isFlagSet("c") {
conf = config.ParseCustom(*configFilename)
} else {
conf = config.Parse()
}

sessionData, err := requests.GetSessionToken(conf.Username, conf.Password)

if err != nil {
Expand Down Expand Up @@ -52,3 +63,14 @@ func main() {

view.Start()
}

func isFlagSet(name string) bool {
found := false
flag.Visit(func(f *flag.Flag) {
if f.Name == name {
found = true
}
})

return found
}

0 comments on commit a7e48ab

Please sign in to comment.