Skip to content

Commit

Permalink
Flags write before arguments in toxiproxy-cli
Browse files Browse the repository at this point in the history
In #294 introduced a breaking change in client argument parsing.
It requires to write [flags before arguments](https://github.com/urfave/cli/blob/master/docs/migrate-v1-to-v2.md#flags-before-args).
Update help texts and documentation to have POSIX way to use
flags and arguments.
  • Loading branch information
miry committed Sep 3, 2021
1 parent 0d6d327 commit b982a66
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# [Unreleased]

* Use CHANGELOG.md for release description (#306, @miry)
* In #294 introduced a breaking change in client argument parsing. It requires
to write [flags before arguments](https://github.com/urfave/cli/blob/master/docs/migrate-v1-to-v2.md#flags-before-args).
Update help texts and documentation. (@miry)

# [2.1.5]

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ documentation on the population helpers.
Alternatively use the CLI to create proxies, e.g.:

```bash
toxiproxy-cli create shopify_test_redis_master -l localhost:26379 -u localhost:6379
toxiproxy-cli create -l localhost:26379 -u localhost:6379 shopify_test_redis_master
```

We recommend a naming such as the above: `<app>_<env>_<data store>_<shard>`.
Expand Down Expand Up @@ -351,7 +351,7 @@ end
Or via the CLI:

```bash
toxiproxy-cli toxic add shopify_test_redis_master -t latency -a latency=1000
toxiproxy-cli toxic add -t latency -a latency=1000 shopify_test_redis_master
```

Please consult your respective client library on usage.
Expand Down Expand Up @@ -492,7 +492,7 @@ fields are consistent with the new data.
### CLI Example

```bash
$ toxiproxy-cli create redis -l localhost:26379 -u localhost:6379
$ toxiproxy-cli create -l localhost:26379 -u localhost:6379 redis
Created new proxy redis
$ toxiproxy-cli list
Listen Upstream Name Enabled Toxics
Expand All @@ -511,7 +511,7 @@ OK
```

```bash
$ toxiproxy-cli toxic add redis -t latency -a latency=1000
$ toxiproxy-cli toxic add -t latency -a latency=1000 redis
Added downstream latency toxic 'latency_downstream' on proxy 'redis'
```

Expand All @@ -526,7 +526,7 @@ $ redis-cli -p 26379
```

```bash
$ toxiproxy-cli toxic remove redis -n latency_downstream
$ toxiproxy-cli toxic remove -n latency_downstream redis
Removed toxic 'latency_downstream' on proxy 'redis'
```

Expand Down
48 changes: 24 additions & 24 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"

toxiproxyServer "github.com/Shopify/toxiproxy"
"github.com/Shopify/toxiproxy/client"
toxiproxy "github.com/Shopify/toxiproxy/client"
"github.com/urfave/cli/v2"
terminal "golang.org/x/term"
)
Expand All @@ -33,38 +33,38 @@ func color(color string) string {
}

var toxicDescription = `
Default Toxics:
latency: delay all data +/- jitter
latency=<ms>,jitter=<ms>
Default Toxics:
latency: delay all data +/- jitter
latency=<ms>,jitter=<ms>
bandwidth: limit to max kb/s
rate=<KB/s>
bandwidth: limit to max kb/s
rate=<KB/s>
slow_close: delay from closing
delay=<ms>
slow_close: delay from closing
delay=<ms>
timeout: stop all data and close after timeout
timeout=<ms>
timeout: stop all data and close after timeout
timeout=<ms>
slicer: slice data into bits with optional delay
average_size=<bytes>,size_variation=<bytes>,delay=<microseconds>
slicer: slice data into bits with optional delay
average_size=<bytes>,size_variation=<bytes>,delay=<microseconds>
toxic add:
usage: toxiproxy-cli toxic add <proxyName> --type <toxicType> --toxicName <toxicName> \
--attribute <key=value> --upstream --downstream
toxic add:
usage: toxiproxy-cli toxic add --type <toxicType> --toxicName <toxicName> \
--attribute <key=value> --upstream --downstream <proxyName>
example: toxiproxy-cli toxic add myProxy -t latency -n myToxic -a latency=100 -a jitter=50
example: toxiproxy-cli toxic add -t latency -n myToxic -a latency=100 -a jitter=50 myProxy
toxic update:
usage: toxiproxy-cli toxic update <proxyName> --toxicName <toxicName> \
--attribute <key1=value1> --attribute <key2=value2>
toxic update:
usage: toxiproxy-cli toxic update --toxicName <toxicName> \
--attribute <key1=value1> --attribute <key2=value2> <proxyName>
example: toxiproxy-cli toxic update myProxy -n myToxic -a jitter=25
example: toxiproxy-cli toxic update -n myToxic -a jitter=25 myProxy
toxic delete:
usage: toxiproxy-cli toxic delete <proxyName> --toxicName <toxicName>
toxic delete:
usage: toxiproxy-cli toxic delete --toxicName <toxicName> <proxyName>
example: toxiproxy-cli toxic delete myProxy -n myToxic
example: toxiproxy-cli toxic delete -n myToxic myProxy
`

var (
Expand Down Expand Up @@ -92,7 +92,7 @@ func main() {
},
{
Name: "create",
Usage: "create a new proxy\n\tusage: 'toxiproxy-cli create <proxyName> --listen <addr> --upstream <addr>'\n",
Usage: "create a new proxy\n\tusage: 'toxiproxy-cli create --listen <addr> --upstream <addr> <proxyName>'\n",
Aliases: []string{"c", "new"},
Flags: []cli.Flag{
&cli.StringFlag{
Expand Down
9 changes: 8 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/Shopify/toxiproxy

go 1.15
go 1.17

require (
github.com/gorilla/mux v1.8.0
Expand All @@ -9,3 +9,10 @@ require (
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
)
2 changes: 1 addition & 1 deletion proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestProxyToDownUpstream(t *testing.T) {

conn := AssertProxyUp(t, proxy.Listen, true)
// Check to make sure the connection is closed
conn.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
conn.SetReadDeadline(time.Now().Add(500 * time.Millisecond))
_, err := conn.Read(make([]byte, 1))
if err != io.EOF {
t.Error("Proxy did not close connection when upstream down", err)
Expand Down

0 comments on commit b982a66

Please sign in to comment.