Skip to content

Commit

Permalink
new NO_COLOR environment variable to disable color output (equally to…
Browse files Browse the repository at this point in the history
… --no-color)
  • Loading branch information
jandelgado committed Feb 8, 2018
1 parent 6604397 commit cc04421
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Swiss army knife for RabbitMQ. Tap/Pub/Sub messages, create/delete/bind queues
and exchanges, inspect broker.

## Contents
## Contents

<!-- vim-markdown-toc GFM -->

Expand All @@ -20,6 +20,7 @@ and exchanges, inspect broker.
* [Environment variables](#environment-variables)
* [Default RabbitMQ broker](#default-rabbitmq-broker)
* [Default RabbitMQ management API endpoint](#default-rabbitmq-management-api-endpoint)
* [Disable color output](#disable-color-output)
* [Examples](#examples)
* [Broker info](#broker-info)
* [Wire-tapping messages](#wire-tapping-messages)
Expand Down Expand Up @@ -116,7 +117,7 @@ Options:
single JSON file. JSON body is base64 encoded. Otherwise
metadata and body (as-is) are saved separately.
-k, --insecure allow insecure TLS connections (no certificate check).
-n, --no-color don't colorize output.
-n, --no-color don't colorize output (also environment variable NO_COLOR)
-r, --routingkey KEY routing key to use in publish mode.
--saveto DIR also save messages and metadata to DIR.
--show-default include default exchange in output info command.
Expand Down Expand Up @@ -175,6 +176,10 @@ $ rabtap info
...
```

#### Disable color output

Set environment variable `NO_COLOR` to disable color output.

### Examples

The following examples expect a RabbitMQ broker running on localhost:5672 and
Expand Down Expand Up @@ -258,7 +263,7 @@ Will consume messages from queue `somequeue` and print out messages in JSON
format (`-j`). Example assumes that `RABTAP_AMQPURI` environment variable is
set.

Note that unlike `tap`, `sub` will consume messages that are in effect
Note that unlike `tap`, `sub` will consume messages that are in effect
removed from the specified queue.

#### Poor mans shovel
Expand Down Expand Up @@ -327,7 +332,7 @@ $ make build-all
## Test data generator

A simple [test data generator tool](app/testgen/README.md) for manual tests is
included in the `app/testgen` directory.
included in the `app/testgen` directory.

## Author

Expand Down
14 changes: 7 additions & 7 deletions app/main/command_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,23 @@ Options:
be read.
QUEUE name of a queue.
-a, --autodelete create auto delete exchange/queue.
--api APIURI connect to given API server. If APIURI is omitted,
--api APIURI connect to given API server. If APIURI is omitted,
the environment variable RABTAP_APIURI will be used.
-b, --bindingkey KEY binding key to use in bind queue command.
--consumers include consumers in output of info command.
-d, --durable create durable exchange/queue.
-h, --help print this help.
-j, --json print/save/publish message metadata and body to a
single JSON file. JSON body is base64 encoded. Otherwise
metadata and body (as-is) are saved separately.
-j, --json print/save/publish message metadata and body to a
single JSON file. JSON body is base64 encoded. Otherwise
metadata and body (as-is) are saved separately.
-k, --insecure allow insecure TLS connections (no certificate check).
-n, --no-color don't colorize output.
-n, --no-color don't colorize output (also environment variable NO_COLOR)
-r, --routingkey KEY routing key to use in publish mode.
--saveto DIR also save messages and metadata to DIR.
--show-default include default exchange in output info command.
--stats include statistics in output of info command.
-t, --type TYPE exchange type [default: fanout].
--uri URI connect to given AQMP broker. If omitted, the
--uri URI connect to given AQMP broker. If omitted, the
environment variable RABTAP_AMQPURI will be used.
-v, --verbose enable verbose mode.
--version show version information and exit.
Expand Down Expand Up @@ -157,7 +157,7 @@ func parseCommonArgs(args map[string]interface{}) commonArgs {
return commonArgs{
Verbose: args["--verbose"].(bool),
InsecureTLS: args["--insecure"].(bool),
NoColor: args["--no-color"].(bool),
NoColor: args["--no-color"].(bool) || (os.Getenv("NO_COLOR") != ""),
JSONFormat: args["--json"].(bool)}
}

Expand Down
19 changes: 17 additions & 2 deletions app/main/command_line_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestCliTapWithMultipleUris(t *testing.T) {
args, err := ParseCommandLineArgs(
[]string{"tap", "--uri=broker1", "exchange1:binding1,exchange2:binding2",
"tap", "--uri=broker2", "exchange3:binding3,exchange4:binding4",
"--saveto", "savedir", "--no-color"})
"--saveto", "savedir"})

assert.Nil(t, err)
assert.Equal(t, TapCmd, args.Cmd)
Expand All @@ -97,7 +97,7 @@ func TestCliTapWithMultipleUris(t *testing.T) {
assert.Equal(t, "exchange4", args.TapConfig[1].Exchanges[1].Exchange)
assert.Equal(t, "binding4", args.TapConfig[1].Exchanges[1].BindingKey)
assert.Equal(t, "savedir", *args.SaveDir)
assert.True(t, args.NoColor)
assert.False(t, args.NoColor)
assert.False(t, args.Verbose)
assert.False(t, args.InsecureTLS)
}
Expand Down Expand Up @@ -353,6 +353,7 @@ func TestCliCreateDurableAutodeleteExchange(t *testing.T) {
assert.True(t, args.Durable)
assert.True(t, args.Autodelete)
}

func TestCliRemoveExchange(t *testing.T) {
args, err := ParseCommandLineArgs(
[]string{"exchange", "rm", "name", "--uri", "uri"})
Expand All @@ -362,3 +363,17 @@ func TestCliRemoveExchange(t *testing.T) {
assert.Equal(t, "name", args.ExchangeName)
assert.Equal(t, "uri", args.AmqpURI)
}

func TestParseNoColorFromEnvironment(t *testing.T) {
const key = "NO_COLOR"
os.Setenv(key, "1")
defer os.Unsetenv(key)

args, err := ParseCommandLineArgs(
[]string{"info", "--api=APIURI"})

assert.Nil(t, err)
assert.Equal(t, InfoCmd, args.Cmd)
assert.Equal(t, "APIURI", args.APIURI)
assert.True(t, args.NoColor)
}

0 comments on commit cc04421

Please sign in to comment.