You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ro...@apache.org on 2018/12/16 18:14:54 UTC

[cloudstack-cloudmonkey] 02/04: output: Fix json output to not do html escape

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

rohit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack-cloudmonkey.git

commit 224f4aa1fc29335479a37bdd92db7b3a9d687ff9
Author: Rohit Yadav <ro...@apache.org>
AuthorDate: Sun Dec 16 02:22:03 2018 +0530

    output: Fix json output to not do html escape
    
    Also updates dependencies using `go mod vendor`.
    
    Signed-off-by: Rohit Yadav <ro...@apache.org>
---
 cmd/output.go                                      |  9 ++---
 go.mod                                             |  2 +-
 go.sum                                             |  2 +
 .../tablewriter/{LICENCE.md => LICENSE.md}         |  2 +-
 vendor/github.com/pkg/term/termios/pty_bsd.go      | 46 ++++++++++------------
 .../term/termios/{pty_bsd.go => pty_freebsd.go}    |  2 -
 vendor/github.com/pkg/term/termios/pty_netbsd.go   | 31 +++++++++++++++
 vendor/github.com/pkg/term/termios/termios_bsd.go  |  2 +-
 vendor/modules.txt                                 |  2 +-
 9 files changed, 62 insertions(+), 36 deletions(-)

diff --git a/cmd/output.go b/cmd/output.go
index 2e649a3..04e9b9c 100644
--- a/cmd/output.go
+++ b/cmd/output.go
@@ -31,11 +31,10 @@ import (
 )
 
 func printJSON(response map[string]interface{}) {
-	jsonOutput, err := json.MarshalIndent(response, "", "  ")
-	if err != nil {
-		fmt.Println("Error during json marshalling:", err.Error())
-	}
-	fmt.Println(string(jsonOutput))
+	enc := json.NewEncoder(os.Stdout)
+	enc.SetEscapeHTML(false)
+	enc.SetIndent("", "  ")
+	enc.Encode(response)
 }
 
 func printTable(response map[string]interface{}) {
diff --git a/go.mod b/go.mod
index 40e9fe0..844a4a3 100644
--- a/go.mod
+++ b/go.mod
@@ -32,7 +32,7 @@ require (
 	github.com/mattn/go-tty v0.0.0-20181127064339-e4f871175a2f // indirect
 	github.com/mitchellh/go-homedir v1.0.0
 	github.com/olekukonko/tablewriter v0.0.1
-	github.com/pkg/term v0.0.0-20180730021639-bffc007b7fd5 // indirect
+	github.com/pkg/term v0.0.0-20181116001808-27bbf2edb814 // indirect
 	github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
 	github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a // indirect
 	golang.org/x/sys v0.0.0-20181019160139-8e24a49d80f8 // indirect
diff --git a/go.sum b/go.sum
index 2a890b1..5c5a566 100644
--- a/go.sum
+++ b/go.sum
@@ -37,6 +37,8 @@ github.com/olekukonko/tablewriter v0.0.1 h1:b3iUnf1v+ppJiOfNX4yxxqfWKMQPZR5yoh8u
 github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
 github.com/pkg/term v0.0.0-20180730021639-bffc007b7fd5 h1:tFwafIEMf0B7NlcxV/zJ6leBIa81D3hgGSgsE5hCkOQ=
 github.com/pkg/term v0.0.0-20180730021639-bffc007b7fd5/go.mod h1:eCbImbZ95eXtAUIbLAuAVnBnwf83mjf6QIVH8SHYwqQ=
+github.com/pkg/term v0.0.0-20181116001808-27bbf2edb814 h1:qWlKm6sU/AyVAgBC1Pg1uuY/X/p4lNYG7t4v8/f4FJE=
+github.com/pkg/term v0.0.0-20181116001808-27bbf2edb814/go.mod h1:eCbImbZ95eXtAUIbLAuAVnBnwf83mjf6QIVH8SHYwqQ=
 github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
 github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
 github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a h1:JSvGDIbmil4Ui/dDdFBExb7/cmkNjyX5F97oglmvCDo=
diff --git a/vendor/github.com/olekukonko/tablewriter/LICENCE.md b/vendor/github.com/olekukonko/tablewriter/LICENSE.md
similarity index 98%
rename from vendor/github.com/olekukonko/tablewriter/LICENCE.md
rename to vendor/github.com/olekukonko/tablewriter/LICENSE.md
index 1fd8484..a0769b5 100644
--- a/vendor/github.com/olekukonko/tablewriter/LICENCE.md
+++ b/vendor/github.com/olekukonko/tablewriter/LICENSE.md
@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
\ No newline at end of file
+THE SOFTWARE.
diff --git a/vendor/github.com/pkg/term/termios/pty_bsd.go b/vendor/github.com/pkg/term/termios/pty_bsd.go
index d1a3baf..45336d4 100644
--- a/vendor/github.com/pkg/term/termios/pty_bsd.go
+++ b/vendor/github.com/pkg/term/termios/pty_bsd.go
@@ -1,41 +1,37 @@
-// +build freebsd openbsd netbsd
+// +build dragonfly openbsd
 
 package termios
 
-import (
-	"fmt"
-	"syscall"
-	"unsafe"
-)
+// #include<stdlib.h>
+import "C"
 
-func posix_openpt(oflag int) (fd uintptr, err error) {
-	// Copied from debian-golang-pty/pty_freebsd.go.
-	r0, _, e1 := syscall.Syscall(syscall.SYS_POSIX_OPENPT, uintptr(oflag), 0, 0)
-	fd = uintptr(r0)
-	if e1 != 0 {
-		err = e1
-	}
-	return
-}
+import "syscall"
 
 func open_pty_master() (uintptr, error) {
-	return posix_openpt(syscall.O_NOCTTY|syscall.O_RDWR|syscall.O_CLOEXEC)
+	rc := C.posix_openpt(syscall.O_NOCTTY | syscall.O_RDWR)
+	if rc < 0 {
+		return 0, syscall.Errno(rc)
+	}
+	return uintptr(rc), nil
 }
 
 func Ptsname(fd uintptr) (string, error) {
-	var n uintptr
-	err := ioctl(fd, syscall.TIOCGPTN, uintptr(unsafe.Pointer(&n)))
-	if err != nil {
-		return "", err
-	}
-	return fmt.Sprintf("/dev/pts/%d", n), nil
+	slavename := C.GoString(C.ptsname(C.int(fd)))
+	return slavename, nil
 }
 
 func grantpt(fd uintptr) error {
-	var n uintptr
-	return ioctl(fd, syscall.TIOCGPTN, uintptr(unsafe.Pointer(&n)))
+	rc := C.grantpt(C.int(fd))
+	if rc == 0 {
+		return nil
+	}
+	return syscall.Errno(rc)
 }
 
 func unlockpt(fd uintptr) error {
-	return nil
+	rc := C.unlockpt(C.int(fd))
+	if rc == 0 {
+		return nil
+	}
+	return syscall.Errno(rc)
 }
diff --git a/vendor/github.com/pkg/term/termios/pty_bsd.go b/vendor/github.com/pkg/term/termios/pty_freebsd.go
similarity index 95%
copy from vendor/github.com/pkg/term/termios/pty_bsd.go
copy to vendor/github.com/pkg/term/termios/pty_freebsd.go
index d1a3baf..e4b933a 100644
--- a/vendor/github.com/pkg/term/termios/pty_bsd.go
+++ b/vendor/github.com/pkg/term/termios/pty_freebsd.go
@@ -1,5 +1,3 @@
-// +build freebsd openbsd netbsd
-
 package termios
 
 import (
diff --git a/vendor/github.com/pkg/term/termios/pty_netbsd.go b/vendor/github.com/pkg/term/termios/pty_netbsd.go
new file mode 100644
index 0000000..a40e7f9
--- /dev/null
+++ b/vendor/github.com/pkg/term/termios/pty_netbsd.go
@@ -0,0 +1,31 @@
+package termios
+
+import (
+	"bytes"
+
+	"golang.org/x/sys/unix"
+)
+
+func open_pty_master() (uintptr, error) {
+	fd, err := unix.Open("/dev/ptmx", unix.O_NOCTTY|unix.O_RDWR, 0666)
+	if err != nil {
+		return 0, err
+	}
+	return uintptr(fd), nil
+}
+
+func Ptsname(fd uintptr) (string, error) {
+	ptm, err := unix.IoctlGetPtmget(int(fd), unix.TIOCPTSNAME)
+	if err != nil {
+		return "", err
+	}
+	return string(ptm.Sn[:bytes.IndexByte(ptm.Sn[:], 0)]), nil
+}
+
+func grantpt(fd uintptr) error {
+	return unix.IoctlSetInt(int(fd), unix.TIOCGRANTPT, 0)
+}
+
+func unlockpt(fd uintptr) error {
+	return nil
+}
diff --git a/vendor/github.com/pkg/term/termios/termios_bsd.go b/vendor/github.com/pkg/term/termios/termios_bsd.go
index 7015065..cf1db3e 100644
--- a/vendor/github.com/pkg/term/termios/termios_bsd.go
+++ b/vendor/github.com/pkg/term/termios/termios_bsd.go
@@ -1,4 +1,4 @@
-// +build darwin freebsd openbsd netbsd
+// +build darwin freebsd openbsd netbsd dragonfly
 
 package termios
 
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 2495f04..38ea648 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -20,7 +20,7 @@ github.com/mattn/go-tty
 github.com/mitchellh/go-homedir
 # github.com/olekukonko/tablewriter v0.0.1
 github.com/olekukonko/tablewriter
-# github.com/pkg/term v0.0.0-20180730021639-bffc007b7fd5
+# github.com/pkg/term v0.0.0-20181116001808-27bbf2edb814
 github.com/pkg/term/termios
 # golang.org/x/sys v0.0.0-20181019160139-8e24a49d80f8
 golang.org/x/sys/unix