Add device name to Keybase
This commit is contained in:
14
keybase.go
14
keybase.go
@ -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 {
|
||||
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
7
types.go
@ -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 {
|
||||
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"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user