Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c9a2bd80bc |
10
chat.go
10
chat.go
@ -37,7 +37,15 @@ func getNewMessages(k *Keybase, subs *subscriptionChannels, execOptions []string
|
|||||||
execString = append(execString, execOptions...)
|
execString = append(execString, execOptions...)
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
execCmd := exec.Command(k.Path, execString...)
|
cmd := make([]string, 0)
|
||||||
|
|
||||||
|
if k.HomePath != "" {
|
||||||
|
cmd = append(cmd, "--home", k.HomePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = append(cmd, execString...)
|
||||||
|
|
||||||
|
execCmd := exec.Command(k.ExePath, cmd...)
|
||||||
stdOut, _ := execCmd.StdoutPipe()
|
stdOut, _ := execCmd.StdoutPipe()
|
||||||
execCmd.Start()
|
execCmd.Start()
|
||||||
scanner := bufio.NewScanner(stdOut)
|
scanner := bufio.NewScanner(stdOut)
|
||||||
|
|||||||
34
keybase.go
34
keybase.go
@ -21,13 +21,33 @@ const (
|
|||||||
CHAT string = "chat"
|
CHAT string = "chat"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// New returns a new Keybase
|
||||||
|
func New(opts ...KeybaseOpt) *Keybase {
|
||||||
|
k := &Keybase{ExePath: "keybase"}
|
||||||
|
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt.apply(k)
|
||||||
|
}
|
||||||
|
|
||||||
|
s := k.status()
|
||||||
|
k.Version = k.version()
|
||||||
|
k.LoggedIn = s.LoggedIn
|
||||||
|
if k.LoggedIn {
|
||||||
|
k.Username = s.Username
|
||||||
|
k.Device = s.Device.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
return k
|
||||||
|
}
|
||||||
|
|
||||||
// NewKeybase returns a new Keybase. Optionally, you can pass a string containing the path to the Keybase executable as the first argument.
|
// NewKeybase returns a new Keybase. Optionally, you can pass a string containing the path to the Keybase executable as the first argument.
|
||||||
|
// This is deprecated and will be removed in a future update. Use New() instead.
|
||||||
func NewKeybase(path ...string) *Keybase {
|
func NewKeybase(path ...string) *Keybase {
|
||||||
k := &Keybase{}
|
k := &Keybase{}
|
||||||
if len(path) < 1 {
|
if len(path) < 1 {
|
||||||
k.Path = "keybase"
|
k.ExePath = "keybase"
|
||||||
} else {
|
} else {
|
||||||
k.Path = path[0]
|
k.ExePath = path[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
s := k.status()
|
s := k.status()
|
||||||
@ -42,7 +62,15 @@ func NewKeybase(path ...string) *Keybase {
|
|||||||
|
|
||||||
// Exec executes the given Keybase command
|
// Exec executes the given Keybase command
|
||||||
func (k *Keybase) Exec(command ...string) ([]byte, error) {
|
func (k *Keybase) Exec(command ...string) ([]byte, error) {
|
||||||
out, err := exec.Command(k.Path, command...).Output()
|
cmd := make([]string, 0)
|
||||||
|
|
||||||
|
if k.HomePath != "" {
|
||||||
|
cmd = append(cmd, "--home", k.HomePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = append(cmd, command...)
|
||||||
|
|
||||||
|
out, err := exec.Command(k.ExePath, cmd...).Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, err
|
return []byte{}, err
|
||||||
}
|
}
|
||||||
|
|||||||
34
types.go
34
types.go
@ -20,6 +20,37 @@ type RunOptions struct {
|
|||||||
FilterChannels []chat1.ChatChannel // Only subscribe to messages from specified channels
|
FilterChannels []chat1.ChatChannel // Only subscribe to messages from specified channels
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// KeybaseOpt configures a Keybase
|
||||||
|
type KeybaseOpt interface {
|
||||||
|
apply(kb *Keybase)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetExePath sets the path to the Keybase executable
|
||||||
|
func SetExePath(path string) KeybaseOpt {
|
||||||
|
return setExePath{path}
|
||||||
|
}
|
||||||
|
|
||||||
|
type setExePath struct {
|
||||||
|
path string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o setExePath) apply(kb *Keybase) {
|
||||||
|
kb.ExePath = o.path
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetHomePath sets the path to the Keybase home directory
|
||||||
|
func SetHomePath(path string) KeybaseOpt {
|
||||||
|
return setHomePath{path}
|
||||||
|
}
|
||||||
|
|
||||||
|
type setHomePath struct {
|
||||||
|
path string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o setHomePath) apply(kb *Keybase) {
|
||||||
|
kb.HomePath = o.path
|
||||||
|
}
|
||||||
|
|
||||||
type subscriptionType struct {
|
type subscriptionType struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
@ -954,7 +985,8 @@ type userBlocks struct {
|
|||||||
|
|
||||||
// Keybase holds basic information about the local Keybase executable
|
// Keybase holds basic information about the local Keybase executable
|
||||||
type Keybase struct {
|
type Keybase struct {
|
||||||
Path string
|
HomePath string
|
||||||
|
ExePath string
|
||||||
Username string
|
Username string
|
||||||
LoggedIn bool
|
LoggedIn bool
|
||||||
Version string
|
Version string
|
||||||
|
|||||||
Reference in New Issue
Block a user