Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9CE2E200CC8 for ; Fri, 14 Jul 2017 20:40:23 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9B4A6161088; Fri, 14 Jul 2017 18:40:23 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id BA802160CFE for ; Fri, 14 Jul 2017 20:40:22 +0200 (CEST) Received: (qmail 25913 invoked by uid 500); 14 Jul 2017 18:40:21 -0000 Mailing-List: contact commits-help@openwhisk.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openwhisk.apache.org Delivered-To: mailing list commits@openwhisk.apache.org Received: (qmail 25901 invoked by uid 99); 14 Jul 2017 18:40:21 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Jul 2017 18:40:21 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 543268757D; Fri, 14 Jul 2017 18:40:21 +0000 (UTC) Date: Fri, 14 Jul 2017 18:40:21 +0000 To: "commits@openwhisk.apache.org" Subject: [incubator-openwhisk] branch master updated: Externalize access to a few CLI methods to facilitate access across packages (#2483) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <150005762120.5529.11301548012243812393@gitbox.apache.org> From: berstler@apache.org Reply-To: "commits@openwhisk.apache.org" X-Git-Host: gitbox.apache.org X-Git-Repo: incubator-openwhisk X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: e45288e53ae1164f782248410ab4b50f7022f1ad X-Git-Newrev: 11beb56c59864d9469a8a9a972a67ab38b90cd39 X-Git-Rev: 11beb56c59864d9469a8a9a972a67ab38b90cd39 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated archived-at: Fri, 14 Jul 2017 18:40:23 -0000 This is an automated email from the ASF dual-hosted git repository. berstler pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git The following commit(s) were added to refs/heads/master by this push: new 11beb56 Externalize access to a few CLI methods to facilitate access across packages (#2483) 11beb56 is described below commit 11beb56c59864d9469a8a9a972a67ab38b90cd39 Author: Mark Deuser AuthorDate: Fri Jul 14 14:40:18 2017 -0400 Externalize access to a few CLI methods to facilitate access across packages (#2483) - Also move properties file reading/loading to when the command is executed, not at binary load time --- tools/cli/go-whisk-cli/commands/api.go | 4 ++-- tools/cli/go-whisk-cli/commands/commands.go | 17 +++++++++-------- tools/cli/go-whisk-cli/commands/property.go | 16 ++++++++-------- tools/cli/go-whisk-cli/commands/util.go | 6 +++--- tools/cli/go-whisk-cli/wski18n/resources/en_US.all.json | 4 ++++ tools/cli/go-whisk/whisk/client.go | 4 ++-- tools/cli/go-whisk/whisk/sdk.go | 2 +- tools/cli/go-whisk/whisk/util.go | 2 +- 8 files changed, 30 insertions(+), 25 deletions(-) diff --git a/tools/cli/go-whisk-cli/commands/api.go b/tools/cli/go-whisk-cli/commands/api.go index d27a42e..f4d0c37 100644 --- a/tools/cli/go-whisk-cli/commands/api.go +++ b/tools/cli/go-whisk-cli/commands/api.go @@ -1524,7 +1524,7 @@ func getAccessToken() (string, error) { var token string = "DUMMY TOKEN" var err error - props, err := readProps(Properties.PropsFile) + props, err := ReadProps(Properties.PropsFile) if err == nil { if len(props["APIGW_ACCESS_TOKEN"]) > 0 { token = props["APIGW_ACCESS_TOKEN"] @@ -1542,7 +1542,7 @@ func getUserContextId() (string, error) { var guid string var err error - props, err := readProps(Properties.PropsFile) + props, err := ReadProps(Properties.PropsFile) if err == nil { if len(props["AUTH"]) > 0 { guid = strings.Split(props["AUTH"], ":")[0] diff --git a/tools/cli/go-whisk-cli/commands/commands.go b/tools/cli/go-whisk-cli/commands/commands.go index c9e3261..3041c53 100644 --- a/tools/cli/go-whisk-cli/commands/commands.go +++ b/tools/cli/go-whisk-cli/commands/commands.go @@ -19,7 +19,6 @@ package commands import ( "errors" - "fmt" "net/http" "os" @@ -75,14 +74,7 @@ func setupClientConfig(cmd *cobra.Command, args []string) (error){ } func init() { - var err error - err = loadProperties() - if err != nil { - whisk.Debug(whisk.DbgError, "loadProperties() error: %s\n", err) - fmt.Println(err) - os.Exit(whisk.EXITCODE_ERR_GENERAL) - } } func getKeyValueArgs(args []string, argIndex int, parsedArgs []string) ([]string, []string, error) { @@ -211,5 +203,14 @@ func Execute() error { return whiskErr } + err = loadProperties() + if err != nil { + whisk.Debug(whisk.DbgError, "loadProperties() error: %s\n", err) + errMsg := wski18n.T("Unable to access configuration properties: {{.err}}", map[string]interface{}{"err":err}) + whiskErr := whisk.MakeWskErrorFromWskError(errors.New(errMsg), err, whisk.EXITCODE_ERR_GENERAL, + whisk.DISPLAY_MSG, whisk.DISPLAY_USAGE) + return whiskErr + } + return WskCmd.Execute() } diff --git a/tools/cli/go-whisk-cli/commands/property.go b/tools/cli/go-whisk-cli/commands/property.go index dc165dc..4ddc796 100644 --- a/tools/cli/go-whisk-cli/commands/property.go +++ b/tools/cli/go-whisk-cli/commands/property.go @@ -68,7 +68,7 @@ var propertySetCmd = &cobra.Command{ var werr *whisk.WskError = nil // get current props - props, err := readProps(Properties.PropsFile) + props, err := ReadProps(Properties.PropsFile) if err != nil { whisk.Debug(whisk.DbgError, "readProps(%s) failed: %s\n", Properties.PropsFile, err) errStr := wski18n.T("Unable to set the property value: {{.err}}", map[string]interface{}{"err": err}) @@ -146,7 +146,7 @@ var propertySetCmd = &cobra.Command{ } } - err = writeProps(Properties.PropsFile, props) + err = WriteProps(Properties.PropsFile, props) if err != nil { whisk.Debug(whisk.DbgError, "writeProps(%s, %#v) failed: %s\n", Properties.PropsFile, props, err) errStr := fmt.Sprintf( @@ -172,7 +172,7 @@ var propertyUnsetCmd = &cobra.Command{ SilenceErrors: true, RunE: func(cmd *cobra.Command, args []string) error { var okMsg string = "" - props, err := readProps(Properties.PropsFile) + props, err := ReadProps(Properties.PropsFile) if err != nil { whisk.Debug(whisk.DbgError, "readProps(%s) failed: %s\n", Properties.PropsFile, err) errStr := fmt.Sprintf( @@ -228,7 +228,7 @@ var propertyUnsetCmd = &cobra.Command{ } } - err = writeProps(Properties.PropsFile, props) + err = WriteProps(Properties.PropsFile, props) if err != nil { whisk.Debug(whisk.DbgError, "writeProps(%s, %#v) failed: %s\n", Properties.PropsFile, props, err) errStr := fmt.Sprintf( @@ -349,7 +349,7 @@ func setDefaultProperties() { // Properties.CLIVersion value is set from main's init() } -func getPropertiesFilePath() (propsFilePath string, werr error) { +func GetPropertiesFilePath() (propsFilePath string, werr error) { var envExists bool // Environment variable overrides the default properties file path @@ -381,16 +381,16 @@ func loadProperties() error { setDefaultProperties() - Properties.PropsFile, err = getPropertiesFilePath() + Properties.PropsFile, err = GetPropertiesFilePath() if err != nil { return nil - //whisk.Debug(whisk.DbgError, "getPropertiesFilePath() failed: %s\n", err) + //whisk.Debug(whisk.DbgError, "GetPropertiesFilePath() failed: %s\n", err) //errStr := fmt.Sprintf("Unable to load the properties file: %s", err) //werr := whisk.MakeWskError(errors.New(errStr), whisk.EXITCODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE) //return werr } - props, err := readProps(Properties.PropsFile) + props, err := ReadProps(Properties.PropsFile) if err != nil { whisk.Debug(whisk.DbgError, "readProps(%s) failed: %s\n", Properties.PropsFile, err) errStr := wski18n.T("Unable to read the properties file '{{.filename}}': {{.err}}", diff --git a/tools/cli/go-whisk-cli/commands/util.go b/tools/cli/go-whisk-cli/commands/util.go index d8cea19..3bd6cee 100644 --- a/tools/cli/go-whisk-cli/commands/util.go +++ b/tools/cli/go-whisk-cli/commands/util.go @@ -950,7 +950,7 @@ func min (a int, b int) int { return b } -func readProps(path string) (map[string]string, error) { +func ReadProps(path string) (map[string]string, error) { props := map[string]string{} @@ -982,7 +982,7 @@ func readProps(path string) (map[string]string, error) { } -func writeProps(path string, props map[string]string) error { +func WriteProps(path string, props map[string]string) error { file, err := os.Create(path) if err != nil { @@ -1010,7 +1010,7 @@ func writeProps(path string, props map[string]string) error { func getSpaceGuid() (string, error) { // get current props - props, err := readProps(Properties.PropsFile) + props, err := ReadProps(Properties.PropsFile) if err != nil { whisk.Debug(whisk.DbgError, "readProps(%s) failed: %s\n", Properties.PropsFile, err) errStr := wski18n.T("Unable to obtain the `auth` property value: {{.err}}", map[string]interface{}{"err": err}) diff --git a/tools/cli/go-whisk-cli/wski18n/resources/en_US.all.json b/tools/cli/go-whisk-cli/wski18n/resources/en_US.all.json index 535f958..7d3929e 100644 --- a/tools/cli/go-whisk-cli/wski18n/resources/en_US.all.json +++ b/tools/cli/go-whisk-cli/wski18n/resources/en_US.all.json @@ -381,6 +381,10 @@ "translation": "Unable to read the properties file '{{.filename}}': {{.err}}" }, { + "id": "Unable to access configuration properties: {{.err}}", + "translation": "Unable to access configuration properties: {{.err}}" + }, + { "id": "Invalid host address '{{.host}}': {{.err}}", "translation": "Invalid host address '{{.host}}': {{.err}}" }, diff --git a/tools/cli/go-whisk/whisk/client.go b/tools/cli/go-whisk/whisk/client.go index 2405ba5..ab50696 100644 --- a/tools/cli/go-whisk/whisk/client.go +++ b/tools/cli/go-whisk/whisk/client.go @@ -225,7 +225,7 @@ func (c *Client) Do(req *http.Request, v interface{}, ExitWithErrorOnTimeout boo fmt.Printf("[%s]\t%s\n", req.Method, req.URL) if len(req.Header) > 0 { fmt.Println("Req Headers") - printJSON(req.Header) + PrintJSON(req.Header) } if req.Body != nil { fmt.Println("Req Body") @@ -247,7 +247,7 @@ func (c *Client) Do(req *http.Request, v interface{}, ExitWithErrorOnTimeout boo Verbose("Got response with code %d\n", resp.StatusCode) if (IsVerbose() && len(resp.Header) > 0) { fmt.Println("Resp Headers") - printJSON(resp.Header) + PrintJSON(resp.Header) } // Read the response body diff --git a/tools/cli/go-whisk/whisk/sdk.go b/tools/cli/go-whisk/whisk/sdk.go index bdf1102..c19dace 100644 --- a/tools/cli/go-whisk/whisk/sdk.go +++ b/tools/cli/go-whisk/whisk/sdk.go @@ -56,7 +56,7 @@ func (s *SdkService) Install(relFileUrl string) (*http.Response, error) { fmt.Printf("[%s]\t%s\n", req.Method, req.URL) if len(req.Header) > 0 { fmt.Println("Req Headers") - printJSON(req.Header) + PrintJSON(req.Header) } if req.Body != nil { fmt.Println("Req Body") diff --git a/tools/cli/go-whisk/whisk/util.go b/tools/cli/go-whisk/whisk/util.go index 4715d01..d89f3b5 100644 --- a/tools/cli/go-whisk/whisk/util.go +++ b/tools/cli/go-whisk/whisk/util.go @@ -61,7 +61,7 @@ func addRouteOptions(route string, options interface{}) (*url.URL, error) { return u, nil } -func printJSON(v interface{}) { +func PrintJSON(v interface{}) { output, _ := prettyjson.Marshal(v) fmt.Fprintln(color.Output, string(output)) } -- To stop receiving notification emails like this one, please contact ['"commits@openwhisk.apache.org" '].