From b982a66d4c4f00cd5adb8d958b15a94187f49b99 Mon Sep 17 00:00:00 2001 From: Michael Nikitochkin Date: Fri, 3 Sep 2021 12:36:18 +0200 Subject: [PATCH 1/2] Flags write before arguments in toxiproxy-cli 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. --- CHANGELOG.md | 3 +++ README.md | 10 +++++----- cli/cli.go | 48 ++++++++++++++++++++++++------------------------ go.mod | 9 ++++++++- proxy_test.go | 2 +- 5 files changed, 41 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d07fa02..410d9dae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/README.md b/README.md index dd87e5bb..2bb0c432 100644 --- a/README.md +++ b/README.md @@ -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: `___`. @@ -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. @@ -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 @@ -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' ``` @@ -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' ``` diff --git a/cli/cli.go b/cli/cli.go index e3115c01..a9c7f337 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -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" ) @@ -33,38 +33,38 @@ func color(color string) string { } var toxicDescription = ` - Default Toxics: - latency: delay all data +/- jitter - latency=,jitter= + Default Toxics: + latency: delay all data +/- jitter + latency=,jitter= - bandwidth: limit to max kb/s - rate= + bandwidth: limit to max kb/s + rate= - slow_close: delay from closing - delay= + slow_close: delay from closing + delay= - timeout: stop all data and close after timeout - timeout= + timeout: stop all data and close after timeout + timeout= - slicer: slice data into bits with optional delay - average_size=,size_variation=,delay= + slicer: slice data into bits with optional delay + average_size=,size_variation=,delay= - toxic add: - usage: toxiproxy-cli toxic add --type --toxicName \ - --attribute --upstream --downstream + toxic add: + usage: toxiproxy-cli toxic add --type --toxicName \ + --attribute --upstream --downstream - 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 --toxicName \ - --attribute --attribute + toxic update: + usage: toxiproxy-cli toxic update --toxicName \ + --attribute --attribute - 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 --toxicName + toxic delete: + usage: toxiproxy-cli toxic delete --toxicName - example: toxiproxy-cli toxic delete myProxy -n myToxic + example: toxiproxy-cli toxic delete -n myToxic myProxy ` var ( @@ -92,7 +92,7 @@ func main() { }, { Name: "create", - Usage: "create a new proxy\n\tusage: 'toxiproxy-cli create --listen --upstream '\n", + Usage: "create a new proxy\n\tusage: 'toxiproxy-cli create --listen --upstream '\n", Aliases: []string{"c", "new"}, Flags: []cli.Flag{ &cli.StringFlag{ diff --git a/go.mod b/go.mod index 82f91629..5b6cca78 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/Shopify/toxiproxy -go 1.15 +go 1.17 require ( github.com/gorilla/mux v1.8.0 @@ -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 +) diff --git a/proxy_test.go b/proxy_test.go index 212b542f..465b8821 100644 --- a/proxy_test.go +++ b/proxy_test.go @@ -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) From 3bf5e3d320c8db106fbbbd7e82d2c22922a24058 Mon Sep 17 00:00:00 2001 From: Michael Nikitochkin Date: Fri, 3 Sep 2021 14:47:48 +0200 Subject: [PATCH 2/2] Add more clarification about previous implementation. Co-authored-by: Drew Matheson --- CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 410d9dae..e086ee8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,8 @@ # [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) +* Dependency updates in #294 introduced a breaking change in CLI argument parsing. Now [flags must be specified before arguments](https://github.com/urfave/cli/blob/master/docs/migrate-v1-to-v2.md#flags-before-args). Previously, arguments could be specified prior to flags. + Update usage help text and documentation. (@miry) # [2.1.5]