Skip to content

Commit

Permalink
Output rework to comply with redis-cli, --raw support
Browse files Browse the repository at this point in the history
  • Loading branch information
codepope committed Aug 21, 2018
1 parent b957b8f commit 6cd6c54
Show file tree
Hide file tree
Showing 248 changed files with 164,326 additions and 35 deletions.
42 changes: 39 additions & 3 deletions Gopkg.lock

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

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@
[prune]
go-tests = true
unused-packages = true

[[constraint]]
name = "github.com/mattn/go-isatty"
version = "0.0.3"
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ Redli is a Go-based alternative to the official Redis-cli application. It's majo

```text
redli [<flags>] [<commands>...]
```

### Flags

```text
--help Show context-sensitive help (also try --help-long and --help-man).
--debug Enable debug mode.
--long Enable long prompt with host/port
Expand All @@ -24,6 +20,10 @@ Redli is a Go-based alternative to the official Redis-cli application. It's majo
--tls Enable TLS/SSL
--certfile=CERTFILE Self-signed certificate file for validation
--certb64=CERTB64 Self-signed certificate string as base64 for validation
--raw Produce raw output
Args:
[<commands>] Redis commands and values
```

* `URI` URI to connect To. It follow the format of [the provisional IANA spec for Redis URLs](https://www.iana.org/assignments/uri-schemes/prov/redis), but with the option to denote a TLS secured connection with the protocol rediss:.
Expand Down
70 changes: 43 additions & 27 deletions redli.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"

"github.com/gomodule/redigo/redis"
"github.com/mattn/go-isatty"
"github.com/mattn/go-shellwords"
"github.com/peterh/liner"
"gopkg.in/alecthomas/kingpin.v2"
Expand All @@ -30,17 +31,27 @@ var (
redistls = kingpin.Flag("tls", "Enable TLS/SSL").Default("false").Bool()
rediscertfile = kingpin.Flag("certfile", "Self-signed certificate file for validation").Envar("REDIS_CERTFILE").File()
rediscertb64 = kingpin.Flag("certb64", "Self-signed certificate string as base64 for validation").Envar("REDIS_CERTB64").String()
forceraw = kingpin.Flag("raw", "Produce raw output").Bool()
commandargs = kingpin.Arg("commands", "Redis commands and values").Strings()
)

var (
rawrediscommands = Commands{}
conn redis.Conn
raw = false
)

func main() {
kingpin.Parse()

if *forceraw {
raw = true
} else {
if !isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd()) {
raw = true
}
}

cert := []byte{}

if *rediscertfile != nil {
Expand Down Expand Up @@ -115,22 +126,7 @@ func main() {
log.Fatal(err)
}

switch v := result.(type) {
case redis.Error:
fmt.Printf("%s\n", v.Error())
case int64:
fmt.Printf("%d\n", v)
case string:
fmt.Printf("%s\n", v)
case []byte:
fmt.Printf("%s\n", string(v))
case nil:
fmt.Printf("nil\n")
case []interface{}:
for i, j := range v {
fmt.Printf("%d) %s\n", i+1, j)
}
}
printRedisResult(result)

os.Exit(0)
}
Expand Down Expand Up @@ -240,21 +236,41 @@ func main() {

result, err := conn.Do(parts[0], args...)

switch v := result.(type) {
case redis.Error:
printRedisResult(result)
}
}

func printRedisResult(result interface{}) {
switch v := result.(type) {
case redis.Error:
if raw {
fmt.Printf("%s\n", v.Error())
case int64:
} else {
fmt.Printf("(error) %s\n", v.Error())
}
case int64:
if raw {
fmt.Printf("%d\n", v)
case string:
} else {
fmt.Printf("(integer) %d\n", v)
}
case string:
if raw {
fmt.Printf("%s\n", v)
case []byte:
} else {
fmt.Printf("%s\n", v)
}
case []byte:
if raw {
fmt.Printf("%s\n", string(v))
case nil:
fmt.Printf("nil\n")
case []interface{}:
for i, j := range v {
fmt.Printf("%d) %s\n", i+1, j)
}
} else {
fmt.Printf("\"%s\"\n", string(v))
}
case nil:
fmt.Printf("nil\n")
case []interface{}:
for i, j := range v {
fmt.Printf("%d) %s\n", i+1, j)
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions vendor/github.com/mattn/go-isatty/.travis.yml

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

9 changes: 9 additions & 0 deletions vendor/github.com/mattn/go-isatty/LICENSE

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

50 changes: 50 additions & 0 deletions vendor/github.com/mattn/go-isatty/README.md

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

2 changes: 2 additions & 0 deletions vendor/github.com/mattn/go-isatty/doc.go

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

15 changes: 15 additions & 0 deletions vendor/github.com/mattn/go-isatty/isatty_appengine.go

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

18 changes: 18 additions & 0 deletions vendor/github.com/mattn/go-isatty/isatty_bsd.go

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

18 changes: 18 additions & 0 deletions vendor/github.com/mattn/go-isatty/isatty_linux.go

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

19 changes: 19 additions & 0 deletions vendor/github.com/mattn/go-isatty/isatty_linux_ppc64x.go

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

10 changes: 10 additions & 0 deletions vendor/github.com/mattn/go-isatty/isatty_others.go

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

Loading

0 comments on commit 6cd6c54

Please sign in to comment.