Skip to content

Commit

Permalink
Remove a use of the global viper struct
Browse files Browse the repository at this point in the history
  • Loading branch information
gcla committed Jun 5, 2022
1 parent 0117c97 commit 9c15935
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 8 additions & 0 deletions configs/profiles/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ func confStringSlice(v *viper.Viper, name string, def []string) []string {
return res
}

func WriteConfigAs(name string) error {
return writeConfigAs(vDefault, name)
}

func writeConfigAs(v *viper.Viper, name string) error {
return v.WriteConfigAs(name)
}

//======================================================================
// Local Variables:
// mode: Go
Expand Down
4 changes: 1 addition & 3 deletions ui/logsui.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/gcla/termshark/v2/configs/profiles"
"github.com/gcla/termshark/v2/widgets/fileviewer"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)

//======================================================================
Expand All @@ -43,15 +42,14 @@ func openLogsUi(app gowid.IApp) {
}

func openConfigUi(app gowid.IApp) {
viper.SetConfigName("termshark") // no need to include file extension - looks for file called termshark.ini for example
tmp, err := ioutil.TempFile("", "termshark-*.toml")
if err != nil {
OpenError(fmt.Sprintf("Could not create temp file: %v", err), app)
return
}
tmp.Close()

err = viper.WriteConfigAs(tmp.Name())
err = profiles.WriteConfigAs(tmp.Name())
if err != nil {
OpenError(fmt.Sprintf("Could not run config viewer\n\n%v", err), app)
} else {
Expand Down

0 comments on commit 9c15935

Please sign in to comment.