You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by cs...@apache.org on 2017/08/04 19:03:23 UTC

[incubator-openwhisk] branch master updated: Prints bashauto-completion install script to STDOUT (#2520)

This is an automated email from the ASF dual-hosted git repository.

csantanapr 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 8d3c2d2  Prints bashauto-completion install script to STDOUT (#2520)
8d3c2d2 is described below

commit 8d3c2d207db997963481fed3327612cac8fa2aee
Author: Benjamin Poole <Be...@ibm.com>
AuthorDate: Fri Aug 4 15:03:20 2017 -0400

    Prints bashauto-completion install script to STDOUT (#2520)
    
    * Prints bash-completion script to STDOUT
    
    * Update docs to include Linux/Mac bash verisons needed
    
    * Reverted to original install but now includes --stdout flag
---
 docs/cli.md                                        | 31 ++++++++++++++++++++-
 .../src/test/scala/system/basic/WskSdkTests.scala  |  6 ++++
 tools/cli/go-whisk-cli/commands/flags.go           |  5 ++++
 tools/cli/go-whisk-cli/commands/sdk.go             | 32 +++++++++++++++-------
 .../go-whisk-cli/wski18n/resources/en_US.all.json  | 10 ++++++-
 tools/ubuntu-setup/bashprofile.sh                  |  1 -
 tools/vagrant/Vagrantfile                          |  2 +-
 7 files changed, 73 insertions(+), 14 deletions(-)

diff --git a/docs/cli.md b/docs/cli.md
index fc8890e..92c5483 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -2,7 +2,7 @@
 
 OpenWhisk offers a powerful command line interface that allows complete management of all aspects of the system.
 
-## Setting up the OpenWhisk CLI 
+## Setting up the OpenWhisk CLI
 
 - Building OpenWhisk from a cloned repository results in the generation of the command line interface. The generated CLIs are located in `openwhisk/bin/`. The main CLI is located in `openwhisk/bin/wsk` that runs on the operating system, and CPU architecture on which it was built. Executables for other operating system, and CPU architectures are located in the following directories: `openwhisk/bin/mac/`, `openwhisk/bin/linux/`, `openwhisk/bin/windows/`.
 
@@ -38,6 +38,35 @@ you can run the following command from your `openwhisk` directory:
 
 To verify your CLI setup, try [creating and running an action](#openwhisk-hello-world-example).
 
+### Configure command completion for Openwhisk CLI
+
+For bash command completion to work, bash 4.1 or newer is required. The most recent Linux distributions should have the correct version of bash but Mac users will most likely have an older version.
+Mac users can check their bash version and update it by running the following commands:
+
+```
+bash --version
+brew install bash-completion
+```
+
+To download the bash command completion to your local directory, run the following command:
+
+```
+wsk sdk install bashauto
+```
+The command script `wsk_cli_bash_completion.sh` will now be in your current directory. To enable command line completion of wsk commands, source the auto completion script into your bash environment.
+
+```
+source wsk_cli_bash_completion.sh
+```
+
+Alternatively, to install bash command completion, run the following command:
+
+```
+eval "`wsk sdk install bashauto --stdout`"
+```
+
+**Note:** Every time a new terminal is opened, this command must run to enable bash command completion. Alternatively, adding the previous command to the `.bashrc` or `.profile` will prevent this.
+
 ## Using the OpenWhisk CLI
 
 After you have configured your environment, you can begin using the OpenWhisk CLI to do the following:
diff --git a/tests/src/test/scala/system/basic/WskSdkTests.scala b/tests/src/test/scala/system/basic/WskSdkTests.scala
index 107a6fb..ac448b1 100644
--- a/tests/src/test/scala/system/basic/WskSdkTests.scala
+++ b/tests/src/test/scala/system/basic/WskSdkTests.scala
@@ -108,4 +108,10 @@ class WskSdkTests
         }
     }
 
+    it should "print bash command completion script to STDOUT" in {
+        val msg = "bash completion for wsk"    // Subject to change, dependent on Cobra script
+
+        val stdout = wsk.cli(Seq("sdk", "install", "bashauto", "--stdout")).stdout
+        stdout should include(msg)
+    }
 }
diff --git a/tools/cli/go-whisk-cli/commands/flags.go b/tools/cli/go-whisk-cli/commands/flags.go
index d506109..b535af5 100644
--- a/tools/cli/go-whisk-cli/commands/flags.go
+++ b/tools/cli/go-whisk-cli/commands/flags.go
@@ -106,6 +106,11 @@ type Flags struct {
         summary bool
     }
 
+    //sdk
+    sdk struct {
+        stdout bool
+    }
+
     // api
     api struct {
         action     string
diff --git a/tools/cli/go-whisk-cli/commands/sdk.go b/tools/cli/go-whisk-cli/commands/sdk.go
index fb16803..80879ae 100644
--- a/tools/cli/go-whisk-cli/commands/sdk.go
+++ b/tools/cli/go-whisk-cli/commands/sdk.go
@@ -74,17 +74,27 @@ var sdkInstallCmd = &cobra.Command{
         case "ios":
             err = iOSInstall()
         case "bashauto":
-            err = WskCmd.GenBashCompletionFile(BASH_AUTOCOMPLETE_FILENAME)
-            if (err != nil) {
-                whisk.Debug(whisk.DbgError, "GenBashCompletionFile('%s`) error: \n", BASH_AUTOCOMPLETE_FILENAME, err)
-                errStr := wski18n.T("Unable to generate '{{.name}}': {{.err}}",
-                        map[string]interface{}{"name": BASH_AUTOCOMPLETE_FILENAME, "err": err})
-                werr := whisk.MakeWskError(errors.New(errStr), whisk.EXITCODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
-                return werr
-            }
-            fmt.Printf(
-                wski18n.T("bash_completion_msg",
+            if flags.sdk.stdout {
+                if err = WskCmd.GenBashCompletion(os.Stdout); err != nil {
+                    whisk.Debug(whisk.DbgError, "GenBashCompletion error: %s\n", err)
+                    errStr := wski18n.T("Unable to output bash command completion {{.err}}",
+                            map[string]interface{}{"err": err})
+                    werr := whisk.MakeWskError(errors.New(errStr), whisk.EXITCODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
+                    return werr
+                }
+             } else {
+                    err = WskCmd.GenBashCompletionFile(BASH_AUTOCOMPLETE_FILENAME)
+                    if (err != nil) {
+                        whisk.Debug(whisk.DbgError, "GenBashCompletionFile('%s`) error: \n", BASH_AUTOCOMPLETE_FILENAME, err)
+                        errStr := wski18n.T("Unable to generate '{{.name}}': {{.err}}",
+                                map[string]interface{}{"name": BASH_AUTOCOMPLETE_FILENAME, "err": err})
+                        werr := whisk.MakeWskError(errors.New(errStr), whisk.EXITCODE_ERR_GENERAL, whisk.DISPLAY_MSG, whisk.NO_DISPLAY_USAGE)
+                        return werr
+                    }
+                    fmt.Printf(
+                        wski18n.T("bash_completion_msg",
                     map[string]interface{}{"name": BASH_AUTOCOMPLETE_FILENAME}))
+             }
         default:
             whisk.Debug(whisk.DbgError, "Invalid component argument '%s'\n", component)
             errStr := wski18n.T("The SDK component argument '{{.component}}' is invalid. Valid components are docker, ios and bashauto",
@@ -238,6 +248,8 @@ func sdkInstall(componentName string) error {
 }
 
 func init() {
+    sdkInstallCmd.Flags().BoolVarP(&flags.sdk.stdout, "stdout", "s", false, wski18n.T("prints bash command completion script to stdout"))
+
     sdkCmd.AddCommand(sdkInstallCmd)
 
     sdkMap = make(map[string]*sdkInfo)
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 9b513a3..5608728 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
@@ -1518,5 +1518,13 @@
   {
     "id": "get action url",
     "translation": "get action url"
-  }
+  },
+  {
+    "id": "Unable to output bash command completion {{.err}}",
+    "translation": "Unable to output bash command completion {{.err}}"
+},
+{
+    "id": "prints bash command completion script to stdout",
+    "translation": "prints bash command completion script to stdout"
+}
 ]
diff --git a/tools/ubuntu-setup/bashprofile.sh b/tools/ubuntu-setup/bashprofile.sh
index e0ad9f9..b7cf311 100644
--- a/tools/ubuntu-setup/bashprofile.sh
+++ b/tools/ubuntu-setup/bashprofile.sh
@@ -1,5 +1,4 @@
 # Adds openwhisk bin to bash profile
 echo 'export PATH=$HOME/openwhisk/bin:$PATH' > "$HOME/.bash_profile"
 # Adds tab completion
-echo 'eval "$(register-python-argcomplete wsk)"' >> "$HOME/.bash_profile"
 echo 'eval "$(register-python-argcomplete wskadmin)"' >> "$HOME/.bash_profile"
diff --git a/tools/vagrant/Vagrantfile b/tools/vagrant/Vagrantfile
index 3ab2bba..cfa62fc 100644
--- a/tools/vagrant/Vagrantfile
+++ b/tools/vagrant/Vagrantfile
@@ -155,7 +155,7 @@ $script_end = <<SCRIPT
   chmod +x ${HOME}/bin/wsk
   chown vagrant:vagrant ${HOME}/bin/wsk
   PATH=${PATH}:${HOME}/bin
-  echo 'pushd "$(mktemp -d)" > /dev/null && wsk sdk install bashauto > /dev/null && source wsk_cli_bash_completion.sh && popd > /dev/null' >> $HOME/.bashrc
+  eval "`wsk sdk install bashauto --stdout`"
 
   # Run OpenWhisk CLI
   touch $HOME/.wskprops

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].