Permalink
Browse files

simplify PMB creation

  • Loading branch information...
justone committed Dec 29, 2015
1 parent 36aae61 commit 686f1a0bdfda989bcea27b8b7befc4bb808c7e46
Showing with 15 additions and 23 deletions.
  1. +5 −5 api/pmb.go
  2. +1 −1 copy_key.go
  3. +1 −1 dump_raw.go
  4. +1 −1 get_key.go
  5. +1 −1 introducer.go
  6. +1 −1 notify.go
  7. +1 −1 notify_mobile.go
  8. +1 −1 openurl.go
  9. +1 −1 plugin.go
  10. +1 −1 remotecopy.go
  11. +1 −1 shell.go
  12. +0 −8 util.go
View
@@ -19,17 +19,17 @@ type PMB struct {
config PMBConfig
}
func GetPMB(uris map[string]string) *PMB {
config := getConfig(uris)
func GetPMB(primaryURI string) *PMB {
config := getConfig(primaryURI)
return &PMB{config: config}
}
func getConfig(uris map[string]string) PMBConfig {
func getConfig(primaryURI string) PMBConfig {
config := make(PMBConfig)
if len(uris["primary"]) > 0 {
config["primary"] = uris["primary"]
if len(primaryURI) > 0 {
config["primary"] = primaryURI
} else if primaryURI := os.Getenv("PMB_PRIMARY_URI"); len(primaryURI) > 0 {
config["primary"] = primaryURI
}
View
@@ -9,7 +9,7 @@ type CopyKeyCommand struct {
var copyKeyCommand CopyKeyCommand
func (x *CopyKeyCommand) Execute(args []string) error {
bus := pmb.GetPMB(urisFromOpts(globalOptions))
bus := pmb.GetPMB(globalOptions.Primary)
id := pmb.GenerateRandomID("copyKey")
View
@@ -13,7 +13,7 @@ type DumpRawCommand struct {
var dumpRawCommand DumpRawCommand
func (x *DumpRawCommand) Execute(args []string) error {
bus := pmb.GetPMB(urisFromOpts(globalOptions))
bus := pmb.GetPMB(globalOptions.Primary)
id := pmb.GenerateRandomID("dumpRaw")
View
@@ -14,7 +14,7 @@ type GetKeyCommand struct {
var getKeyCommand GetKeyCommand
func (x *GetKeyCommand) Execute(args []string) error {
bus := pmb.GetPMB(urisFromOpts(globalOptions))
bus := pmb.GetPMB(globalOptions.Primary)
id := pmb.GenerateRandomID("getKey")
View
@@ -33,7 +33,7 @@ func (x *IntroducerCommand) Execute(args []string) error {
}
logrus.Debugf("calling GetPMB")
bus := pmb.GetPMB(urisFromOpts(globalOptions))
bus := pmb.GetPMB(globalOptions.Primary)
var name string
if len(introducerCommand.Name) > 0 {
View
@@ -20,7 +20,7 @@ type NotifyCommand struct {
var notifyCommand NotifyCommand
func (x *NotifyCommand) Execute(args []string) error {
bus := pmb.GetPMB(urisFromOpts(globalOptions))
bus := pmb.GetPMB(globalOptions.Primary)
if len(args) == 0 && len(notifyCommand.Message) == 0 && notifyCommand.Pid == 0 {
return fmt.Errorf("A message is required")
View
@@ -19,7 +19,7 @@ type NotifyMobileCommand struct {
var notifyMobileCommand NotifyMobileCommand
func (x *NotifyMobileCommand) Execute(args []string) error {
bus := pmb.GetPMB(urisFromOpts(globalOptions))
bus := pmb.GetPMB(globalOptions.Primary)
// get necessary Pushover parameters from environment or options
var token string
View
@@ -18,7 +18,7 @@ type OpenURLCommand struct {
var openURLCommand OpenURLCommand
func (x *OpenURLCommand) Execute(args []string) error {
bus := pmb.GetPMB(urisFromOpts(globalOptions))
bus := pmb.GetPMB(globalOptions.Primary)
// grab all args or stdin
var data string
View
@@ -19,7 +19,7 @@ type PluginCommand struct {
var pluginCommand PluginCommand
func (x *PluginCommand) Execute(args []string) error {
bus := pmb.GetPMB(urisFromOpts(globalOptions))
bus := pmb.GetPMB(globalOptions.Primary)
if len(args) == 0 {
return fmt.Errorf("Please specify a command (with args).")
View
@@ -18,7 +18,7 @@ type RemoteCopyCommand struct {
var remoteCopyCommand RemoteCopyCommand
func (x *RemoteCopyCommand) Execute(args []string) error {
bus := pmb.GetPMB(urisFromOpts(globalOptions))
bus := pmb.GetPMB(globalOptions.Primary)
// grab all args or stdin
var data string
View
@@ -15,7 +15,7 @@ type ShellCommand struct {
var shellCommand ShellCommand
func (x *ShellCommand) Execute(args []string) error {
bus := pmb.GetPMB(urisFromOpts(globalOptions))
bus := pmb.GetPMB(globalOptions.Primary)
id := pmb.GenerateRandomID("shell")
View
@@ -16,14 +16,6 @@ func init() {
rand.Seed(time.Now().UnixNano())
}
func urisFromOpts(opts GlobalOptions) map[string]string {
uris := make(map[string]string)
uris["primary"] = opts.Primary
return uris
}
func copyToClipboard(data string) error {
logrus.Infof("copy data: %s\n", strings.Replace(truncate(data, 50), "\n", "\\n", -1))

0 comments on commit 686f1a0

Please sign in to comment.