Browse Source

Add device name to Keybase

main
Sam 5 years ago
parent
commit
fc05a8d710
  1. 14
      keybase.go
  2. 7
      types.go

14
keybase.go

@ -29,6 +29,7 @@ func NewKeybase(path ...string) *Keybase { @@ -29,6 +29,7 @@ func NewKeybase(path ...string) *Keybase {
k.LoggedIn = k.loggedIn()
if k.LoggedIn {
k.Username = k.username()
k.Device = k.device()
}
return k
}
@ -78,6 +79,19 @@ func (k *Keybase) username() string { @@ -78,6 +79,19 @@ func (k *Keybase) username() string {
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 {
cmdOut, err := k.Exec("status", "-j")

7
types.go

@ -518,6 +518,7 @@ type Keybase struct { @@ -518,6 +518,7 @@ type Keybase struct {
Username string
LoggedIn bool
Version string
Device string
}
// Chat holds basic information about a specific conversation
@ -584,9 +585,15 @@ type keybase interface { @@ -584,9 +585,15 @@ type keybase interface {
loggedIn() bool
username() string
version() string
device() string
}
type status struct {
Username string `json:"Username"`
LoggedIn bool `json:"LoggedIn"`
Device device `json:"Device"`
}
type device struct {
Name string `json:"name"`
}

Loading…
Cancel
Save