Github user geomacy commented on a diff in the pull request:

    https://github.com/apache/brooklyn-client/pull/18#discussion_r61274582
  
    --- Diff: br/brooklyn.go ---
    @@ -19,45 +19,73 @@
     package main
     
     import (
    +   "fmt"
        "github.com/apache/brooklyn-client/app"
        "github.com/apache/brooklyn-client/command_factory"
        "github.com/apache/brooklyn-client/command_runner"
        "github.com/apache/brooklyn-client/error_handler"
        "github.com/apache/brooklyn-client/io"
        "github.com/apache/brooklyn-client/net"
    +   "github.com/apache/brooklyn-client/plugin"
        "github.com/apache/brooklyn-client/scope"
        "os"
    +   "os/exec"
        "path/filepath"
     )
     
    -func getNetworkCredentialsFromConfig(yamlMap map[string]interface{}) 
(string, string, string) {
    -   var target, username, password string
    -   target, found := yamlMap["target"].(string)
    -   if found {
    -           auth, found := yamlMap["auth"].(map[string]interface{})
    -           if found {
    -                   creds := auth[target].(map[string]interface{})
    -                   username, found = creds["username"].(string)
    -                   if found {
    -                           password, found = creds["password"].(string)
    -                   }
    -           }
    -   }
    -   return target, username, password
    -}
    -
     func main() {
        config := io.GetConfig()
    -   target, username, password := 
getNetworkCredentialsFromConfig(config.Map)
        //target, username, password := "http://192.168.50.101:8081";, 
"brooklyn", "Sns4Hh9j7l"
    +   target := config.Model.Target
    +   username := config.Model.Auth[target].Username
    +   password := config.Model.Auth[target].Password
        network := net.NewNetwork(target, username, password)
        cmdFactory := command_factory.NewFactory(network, config)
     
        args, scope := scope.ScopeArguments(os.Args)
        cmdRunner := command_runner.NewRunner(scope, cmdFactory)
    -   metaDatas := cmdFactory.CommandMetadatas()
    -   theApp := app.NewApp(filepath.Base(args[0]), cmdRunner, metaDatas...)
    -   if err := theApp.Run(args); nil != err {
    +   metadatas := cmdFactory.CommandMetadatas()
    +   theApp := app.NewApp(filepath.Base(args[0]), cmdRunner, metadatas...)
    +
    +   // try looking for a plugin
    +   rpcServer, err := plugin.NewRpcServer(cmdFactory)
    +   if err != nil {
                error_handler.ErrorExit(err)
        }
    +   if !runPluginIfExists(rpcServer, os.Args[1:], config.Model.Plugins) {
    +           theApp.Run(args)
    +   }
    +}
    +
    +func runPluginIfExists(rpcService *plugin.RpcServer, args []string, 
pluginList map[string]*plugin.PluginMetadata) bool {
    +   for executableName, metadata := range pluginList {
    +           for _, command := range metadata.Commands {
    +                   if command.Name == args[0] || command.Alias == args[0] {
    +                           args[0] = command.Name
    +
    +                           rpcService.Start()
    +                           defer rpcService.Stop()
    +
    +                           pluginArgs := 
append([]string{rpcService.Port()}, args...)
    +
    +                           cmd := exec.Command(executableName, 
pluginArgs...)
    --- End diff --
    
    Better if this ran the plugin using the full path to its installed location 
in $HOME or $BRCLI/plugins; less ambiguity and in particular avoids a clash 
with $GOPATH/bin. We could avoid the requirement to have $HOME or 
$BRCLI/plugins on the PATH by this means.  See also 
https://github.com/apache/brooklyn-client/pull/18/files#r61271120.  


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to