Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Set a default path to keybase if not passed in
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel committed Jun 8, 2016
1 parent 760a184 commit f8dafaf
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ package main
import (
"flag"
"os"
"path/filepath"

"github.com/kardianos/osext"
"github.com/keybase/go-updater"
"github.com/keybase/go-updater/keybase"
"github.com/keybase/go-updater/util"
Expand Down Expand Up @@ -52,6 +54,23 @@ func run(f flags) {
defer util.Close(logFile)
}

// Set default path to keybase if not set
if f.pathToKeybase == "" {
path, err := osext.Executable()
if err != nil {
ulog.Warning("Error determining our executable path: %s", err)
} else {
dir, _ := filepath.Split(path)
pathToKeybase := filepath.Join(dir, "keybase")
ulog.Debugf("Using default path to keybase: %s", pathToKeybase)
f.pathToKeybase = pathToKeybase
}
}

if f.pathToKeybase == "" {
ulog.Warning("Missing -path-to-keybase")
}

switch f.command {
case "check":
if err := updateCheckFromFlags(f, ulog); err != nil {
Expand All @@ -68,11 +87,6 @@ func run(f flags) {

func serviceFromFlags(f flags, ulog logger) *service {
ulog.Infof("Updater %s", updater.Version)

if f.pathToKeybase == "" {
ulog.Warning("Missing -path-to-keybase")
}

ctx, upd := keybase.NewUpdaterContext(f.pathToKeybase, ulog)
return newService(upd, ctx, ulog)
}
Expand Down

0 comments on commit f8dafaf

Please sign in to comment.