You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
55 lines
1.5 KiB
package keybase |
|
|
|
import ( |
|
"fmt" |
|
"os/exec" |
|
) |
|
|
|
// Options holds... run... options... |
|
type Options struct { |
|
// Optional, but required if keybase is not in your path |
|
KeybaseLocation string |
|
|
|
// Only use this if you know what you're doing |
|
HomeDir string |
|
|
|
// Show others a typing notification while the bot is working on a command |
|
EnableTyping bool |
|
|
|
// Turn off Keybase's 'bot lite' mode. Only disable if you need to. |
|
DisableLiteMode bool |
|
|
|
// The size of the channel buffers, may vary on rate of message ingestion |
|
ChannelBufferSize int |
|
} |
|
|
|
// locateKeybase attempts to find the location of the keybase binary in the following order: |
|
// 1. What the user has specified as the location [user specified] |
|
// 2. Looks up the binary location using exec.LookPath [default] |
|
// 3. Returns "keybase" and hopes its pathed on the users system [fallback] |
|
func locateKeybase() (string, error) { |
|
path, err := exec.LookPath("keybase") |
|
if err != nil { |
|
return "", fmt.Errorf("could not determine path for keybase binary: %v", err) |
|
} |
|
return path, nil |
|
} |
|
|
|
// buildBaseCommand adds the homedirectory before the args, when required |
|
func buildArgs(opts Options, args ...string) ([]string, error) { |
|
if len(args) == 0 { |
|
return nil, fmt.Errorf("no arguments") |
|
} |
|
|
|
// initialize slice so we never return a nil object |
|
cmd := make([]string, 0) |
|
if opts.HomeDir != "" { |
|
cmd = append(cmd, "--home", opts.HomeDir) |
|
} |
|
if !opts.DisableLiteMode { |
|
cmd = append(cmd, "--enable-bot-lite-mode") |
|
} |
|
cmd = append(cmd, args...) |
|
|
|
return cmd, nil |
|
}
|
|
|