Skip to content

Commit

Permalink
deprecating WithinOpenWhisk flag (apache#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
pritidesai authored and mrutkows committed Mar 21, 2018
1 parent eaf3b86 commit 7d72ab0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 62 deletions.
44 changes: 0 additions & 44 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@
package cmd

import (
"encoding/json"
"errors"
"fmt"
"os"
"path"
"path/filepath"
"regexp"
"strings"

"github.com/apache/incubator-openwhisk-client-go/whisk"
Expand Down Expand Up @@ -57,53 +53,13 @@ func RootCmdImp(cmd *cobra.Command, args []string) error {
// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if utils.Flags.WithinOpenWhisk {
err := substCmdArgs()
if err != nil {
wskprint.PrintOpenWhiskFromError(err)
return
}
}

if err := RootCmd.Execute(); err != nil {
wskprint.PrintOpenWhiskFromError(err)
os.Exit(-1)
} else {
if utils.Flags.WithinOpenWhisk {
// TODO() Why are we printing success here?
// TODO() maybe return report of what has been deployed.
wskprint.PrintlnOpenWhiskSuccess(wski18n.T(wski18n.ID_MSG_DEPLOYMENT_SUCCEEDED))
}
}
}

// This function is only used when wskdeploy is being called as an Action and its input
// (i.e., command and arguments) is JSON data (map).
func substCmdArgs() error {
// Extract arguments from input JSON string
// { "cmd": ".." } // space-separated arguments

arg := os.Args[1]

// TODO() Move to proper status output/debug/trace
fmt.Println("arg is " + arg)
// unmarshal the string to a JSON object
var obj map[string]interface{}
json.Unmarshal([]byte(arg), &obj)

if v, ok := obj["cmd"].(string); ok {
regex, _ := regexp.Compile("[ ]+")
os.Args = regex.Split("wskdeploy "+strings.TrimSpace(v), -1)
} else {
return errors.New(wski18n.T(wski18n.ID_ERR_JSON_MISSING_KEY_CMD))
}
return nil
}

func init() {
// TODO() move Env var. to some global const
utils.Flags.WithinOpenWhisk = len(os.Getenv("__OW_API_HOST")) > 0

cobra.OnInitialize(initConfig)

// Defining Persistent Flags of Whisk Deploy Root command (wskdeploy)
Expand Down
1 change: 0 additions & 1 deletion utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
)

type WskDeployFlags struct {
WithinOpenWhisk bool // is this running within an OpenWhisk action?
ApiHost string // OpenWhisk API host
Auth string // OpenWhisk API key
Namespace string
Expand Down
34 changes: 17 additions & 17 deletions wski18n/i18n_resources.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7d72ab0

Please sign in to comment.