rabbitmq / rabbitmq-cli

Command line tools for RabbitMQ
Other
105 stars 34 forks source link

New commands for definition management #387

Closed michaelklishin closed 4 years ago

michaelklishin commented 5 years ago

Proposed Changes

This introduces new commands for definition export and import that does not depend on any plugins:

rabbitmqctl export_definitions /tmp/definitions.et --format=erlang --silent
rabbitmqctl import_definitions /tmp/definitions.et --format=erlang --silent
# output as JSON to standard output
rabbitmqctl export_definitions - --format=json --silent | jq
./escript/rabbitmqctl export_definitions - --format=json | ./escript/rabbitmqctl import_definitions --format=json
./escript/rabbitmqctl import_definitions --format=json ./escript/rabbitmqctl import_definitions --format=json ./test/fixtures/files/definitions.json

Part of rabbitmq/rabbitmq-management#749 and depends on other PRs mentioned in that issue.

Types of Changes

Checklist

Further Comments

Part of rabbitmq/rabbitmq-management#749.

michaelklishin commented 4 years ago

@lukebakken ready for another round.

dcorbacho commented 4 years ago

export_definitions with no argument works now 👍

Small formatting issue, it could do with a newline at the end: Successfully started definition import. This process is asynchronous and can take some time.mars:rabbit dparracorbacho$

If we try to import the wrong format, we get a not very helpful crash. Could we return something like invalid format?

mars:rabbit dparracorbacho$ ./escript/rabbitmqctl import_definitions --format erlang kk
Importing definitions in Erlang term format from a file at "kk" ...
Function clause.
Stacktrace:
    (rabbitmqctl) lib/rabbitmqctl.ex:106: RabbitMQCtl.exec_command/2
    (rabbitmqctl) lib/rabbitmqctl.ex:45: RabbitMQCtl.main/1
    (elixir) lib/kernel/cli.ex:121: anonymous fn/3 in Kernel.CLI.exec_fun/2
lukebakken commented 4 years ago

@dcorbacho I just added the newline.

lukebakken commented 4 years ago

@dcorbacho @michaelklishin please see the changes I made in a676abb1f305ee616889d3b4683773bb5dfeff0d

michaelklishin commented 4 years ago

Backported to v3.8.x.