Browse Source

Consolidate the various functions that call keybase status so it only gets called once

main
Sam 5 years ago
parent
commit
74a93b765c
  1. 2
      go.mod
  2. 43
      keybase.go
  3. 4
      types.go

2
go.mod

@ -1,3 +1,3 @@ @@ -1,3 +1,3 @@
module samhofi.us/x/keybase
go 1.12
go 1.13

43
keybase.go

@ -25,11 +25,13 @@ func NewKeybase(path ...string) *Keybase { @@ -25,11 +25,13 @@ func NewKeybase(path ...string) *Keybase {
} else {
k.Path = path[0]
}
s := k.status()
k.Version = k.version()
k.LoggedIn = k.loggedIn()
k.LoggedIn = s.LoggedIn
if k.LoggedIn {
k.Username = k.username()
k.Device = k.device()
k.Username = s.Username
k.Device = s.Device.Name
}
return k
}
@ -66,43 +68,18 @@ func (k *Keybase) NewWallet() Wallet { @@ -66,43 +68,18 @@ func (k *Keybase) NewWallet() Wallet {
}
}
// username returns the username of the currently logged-in Keybase user.
func (k *Keybase) username() string {
cmdOut, err := k.Exec("status", "-j")
if err != nil {
return ""
}
var s status
json.Unmarshal(cmdOut, &s)
return s.Username
}
// device returns the device name of the currently provisioned device.
func (k *Keybase) device() string {
cmdOut, err := k.Exec("status", "-j")
if err != nil {
return ""
}
var s status
json.Unmarshal(cmdOut, &s)
return s.Device.Name
}
// loggedIn returns true if Keybase is currently logged in, otherwise returns false.
func (k *Keybase) loggedIn() bool {
// status returns the results of the `keybase status` command, which includes
// information about the client, and the currently logged-in Keybase user.
func (k *Keybase) status() status {
cmdOut, err := k.Exec("status", "-j")
if err != nil {
return false
return status{}
}
var s status
json.Unmarshal(cmdOut, &s)
return s.LoggedIn
return s
}
// version returns the version string of the client.

4
types.go

@ -582,10 +582,8 @@ type keybase interface { @@ -582,10 +582,8 @@ type keybase interface {
NewTeam(name string) Team
NewWallet() Wallet
Run(handler func(ChatAPI), options ...RunOptions)
loggedIn() bool
username() string
version() string
device() string
status() status
}
type status struct {

Loading…
Cancel
Save