Skip to content

Commit

Permalink
MB-19078, MB-21215 : Allow -q to disable echoing queries in the sourc…
Browse files Browse the repository at this point in the history
…e file. Also add a quiet predefined parameter to be able to set quiet flag during a shell session.

Change-Id: I1d441781859b5935d359e4880bdb138e74ca574b
Reviewed-on: http://review.couchbase.org/68638
Reviewed-by: Johan Larson <johan.larson@couchbase.com>
Reviewed-by: Sitaram Vemulapalli <sitaram.vemulapalli@couchbase.com>
Tested-by: Isha Kandaswamy <isha@couchbase.com>
Reviewed-on: http://review.couchbase.org/73326
Tested-by: Sitaram Vemulapalli <sitaram.vemulapalli@couchbase.com>
  • Loading branch information
ikandaswamy authored and sitaramv committed Feb 8, 2017
1 parent d8b33fb commit cbebea0
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
8 changes: 3 additions & 5 deletions shell/cbq/cmdexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,11 @@ func readAndExec(liner *liner.State) (int, string) {
// Populate the final string to execute
final_input = strings.TrimSpace(final_input)

if final_input == ";" {
continue
// Print the query along with printing the results, only if -q isnt specified.
if !command.QUIET {
io.WriteString(command.W, final_input+"\n")
}

// Print the query along with printing the results
io.WriteString(command.W, final_input+"\n")

//Remove the ; before sending the query to execute
final_input = strings.TrimSuffix(final_input, ";")

Expand Down
16 changes: 13 additions & 3 deletions shell/cbq/command/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"net/url"
"os"
"runtime"
"strconv"
"strings"

"github.com/couchbase/godbc/n1ql"
Expand All @@ -30,7 +31,7 @@ var (
PreDefSV map[string]*Stack = map[string]*Stack{
"histfile": Stack_Helper(),
"batch": Stack_Helper(),
//"autoconfig": Stack_Helper(),
"quiet": Stack_Helper(),
}
)

Expand Down Expand Up @@ -63,11 +64,11 @@ func init() {

}

/*err_code, err_str = PushValue_Helper(false, PreDefSV, "autoconfig", "false")
err_code, err_str = PushValue_Helper(false, PreDefSV, "quiet", strconv.FormatBool(QUIET))
if err_code != 0 {
s_err := HandleError(err_code, err_str)
PrintError(s_err)
}*/
}
}

func SetWriter(Wt io.Writer) {
Expand Down Expand Up @@ -481,7 +482,16 @@ func PushOrSet(args []string, pushvalue bool) (int, string) {
}
}
} else if vble == "batch" {
if args_str != "on" || args_str != "off" {
return errors.BATCH_MODE, ""
}
BATCH = args_str
} else if vble == "quiet" {
var errQ error
QUIET, errQ = strconv.ParseBool(args_str)
if errQ != nil {
return errors.INVALID_INPUT_ARGUMENTS, ""
}
}

err_code, err_str := PushValue_Helper(pushvalue, PreDefSV, vble, args_str)
Expand Down
23 changes: 23 additions & 0 deletions shell/cbq/command/pop.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package command
import (
"encoding/json"
"io"
"strconv"
"strings"

"github.com/couchbase/godbc/n1ql"
Expand Down Expand Up @@ -190,6 +191,28 @@ func (this *Pop) ExecCommand(args []string) (int, string) {
if err_code != 0 {
return err_code, err_str
}
} else if vble == "quiet" {
st_val, ok := PreDefSV["quiet"]
if ok {
newval, err_code, err_str := st_val.Top()
if err_code != 0 {
return err_code, err_str
}
nval = ValToStr(newval)
nval = handleStrings(nval)
} else {
err_code, err_str := PushValue_Helper(false, PreDefSV, "quiet", strconv.FormatBool(false))
if err_code != 0 {
return err_code, err_str

}
nval = strconv.FormatBool(false)
}

// Set QUIET boolean value from nval string.
// Dont need to worry about error handling here as we make sure we push correct values
// into the stack.
QUIET, _ = strconv.ParseBool(nval)
}

}
Expand Down
10 changes: 10 additions & 0 deletions shell/cbq/command/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package command

import (
"io"
"strconv"
"strings"

"github.com/couchbase/godbc/n1ql"
Expand Down Expand Up @@ -113,6 +114,15 @@ func (this *Unset) ExecCommand(args []string) (int, string) {

}

if vble == "quiet" {
err_code, err_str = PushValue_Helper(false, PreDefSV, "quiet", strconv.FormatBool(false))
if err_code != 0 {
return err_code, err_str

}
QUIET = false
}

//Print the path to histfile
err_code, err_str = printPath(HISTFILE)
if err_code != 0 {
Expand Down
14 changes: 13 additions & 1 deletion shell/cbq/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"io"
"os"
"path/filepath"
"strconv"
"strings"
"unicode"

Expand Down Expand Up @@ -65,7 +66,8 @@ func init() {
/*
Option : -quiet
Default value : false
Enable/Disable startup connection message for the shell
Enable/Disable startup connection message for the shell. Also disable echoing queries
when using \SOURCE or -f.
*/
var quietFlag bool

Expand Down Expand Up @@ -519,7 +521,17 @@ func main() {
}

//Set QUIET to enable/disable histfile path message
//If quiet is true
command.QUIET = quietFlag
if quietFlag {
// SET the quiet mode here
//SET batch mode here
err_code, err_str := command.PushValue_Helper(true, command.PreDefSV, "quiet", strconv.FormatBool(quietFlag))
if err_code != 0 {
s_err := command.HandleError(err_code, err_str)
command.PrintError(s_err)
}
}

if timeoutFlag != "0ms" {
n1ql.SetQueryParams("timeout", timeoutFlag)
Expand Down

0 comments on commit cbebea0

Please sign in to comment.