Skip to content

Commit 12fbcbb

Browse files
New command group: exchanges, closes #63
1 parent 549b113 commit 12fbcbb

File tree

5 files changed

+339
-5
lines changed

5 files changed

+339
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Enhancements
66

7+
* `exchanges` is a new command group for operations on exchanges
78
* `global_parameters` is a new command group for operations on [global runtime parameters](https://www.rabbitmq.com/docs/parameters)
89
* `nodes` is a new command group for operations on nodes
910
* `parameters` is a new command group for operations on [runtime parameters](https://www.rabbitmq.com/docs/parameters)

src/cli.rs

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ pub fn parser(pre_flight_settings: PreFlightSettings) -> Command {
8080
))
8181
.subcommand_value_name("deprecated feature")
8282
.subcommands(deprecated_features_subcommands(pre_flight_settings.clone()));
83+
let exchanges_group = Command::new("exchanges")
84+
.about("Operations on exchanges")
85+
.infer_subcommands(pre_flight_settings.infer_subcommands)
86+
.infer_long_args(pre_flight_settings.infer_long_options)
87+
.subcommand_value_name("exchange")
88+
.subcommands(exchanges_subcommands(pre_flight_settings.clone()));
8389
let export_group = Command::new("export")
8490
.about("See 'definitions export'")
8591
.infer_subcommands(pre_flight_settings.infer_subcommands)
@@ -274,6 +280,7 @@ pub fn parser(pre_flight_settings: PreFlightSettings) -> Command {
274280
definitions_group,
275281
delete_group,
276282
deprecated_features_group,
283+
exchanges_group,
277284
export_group,
278285
feature_flags_group,
279286
federation_group,
@@ -1801,6 +1808,132 @@ Examples:
18011808
.map(|cmd| cmd.infer_long_args(pre_flight_settings.infer_long_options))
18021809
}
18031810

1811+
fn exchanges_subcommands(pre_flight_settings: PreFlightSettings) -> [Command; 5] {
1812+
let bind_cmd = Command::new("bind")
1813+
.about("Creates a binding between a source exchange and a destination (a queue or an exchange)")
1814+
.arg(
1815+
Arg::new("source")
1816+
.long("source")
1817+
.help("source exchange")
1818+
.required(true),
1819+
)
1820+
.arg(
1821+
Arg::new("destination_type")
1822+
.long("destination-type")
1823+
.help("destination type: exchange or queue")
1824+
.required(true)
1825+
.value_parser(value_parser!(BindingDestinationType)),
1826+
)
1827+
.arg(
1828+
Arg::new("destination")
1829+
.long("destination")
1830+
.help("destination exchange/queue name")
1831+
.required(true),
1832+
)
1833+
.arg(
1834+
Arg::new("routing_key")
1835+
.long("routing-key")
1836+
.help("routing key")
1837+
.required(true),
1838+
)
1839+
.arg(
1840+
Arg::new("arguments")
1841+
.long("arguments")
1842+
.help("additional arguments")
1843+
.required(false)
1844+
.default_value("{}")
1845+
.value_parser(value_parser!(String)),
1846+
);
1847+
let declare_cmd = Command::new("declare")
1848+
.about("Declares an exchange")
1849+
.arg(
1850+
Arg::new("name")
1851+
.long("name")
1852+
.help("exchange name")
1853+
.required(true),
1854+
)
1855+
.arg(
1856+
Arg::new("type")
1857+
.long("type")
1858+
.help("exchange type")
1859+
.value_parser(value_parser!(ExchangeType))
1860+
.required(false),
1861+
)
1862+
.arg(
1863+
Arg::new("durable")
1864+
.long("durable")
1865+
.help("should it persist after a restart")
1866+
.required(false)
1867+
.value_parser(value_parser!(bool)),
1868+
)
1869+
.arg(
1870+
Arg::new("auto_delete")
1871+
.long("auto-delete")
1872+
.help("should it be deleted when the last queue is unbound")
1873+
.required(false)
1874+
.value_parser(value_parser!(bool)),
1875+
)
1876+
.arg(
1877+
Arg::new("arguments")
1878+
.long("arguments")
1879+
.help("additional exchange arguments")
1880+
.required(false)
1881+
.default_value("{}")
1882+
.value_parser(value_parser!(String)),
1883+
);
1884+
let idempotently_arg = Arg::new("idempotently")
1885+
.long("idempotently")
1886+
.value_parser(value_parser!(bool))
1887+
.action(ArgAction::SetTrue)
1888+
.help("do not consider 404 Not Found API responses to be errors")
1889+
.required(false);
1890+
let delete_cmd = Command::new("delete")
1891+
.about("Deletes an exchange")
1892+
.arg(
1893+
Arg::new("name")
1894+
.long("name")
1895+
.help("exchange name")
1896+
.required(true),
1897+
)
1898+
.arg(idempotently_arg.clone());
1899+
let list_cmd = Command::new("list").long_about("Lists exchanges");
1900+
let unbind_cmd = Command::new("unbind")
1901+
.about("Deletes a binding")
1902+
.arg(
1903+
Arg::new("source")
1904+
.long("source")
1905+
.help("source exchange")
1906+
.required(true),
1907+
)
1908+
.arg(
1909+
Arg::new("destination_type")
1910+
.long("destination-type")
1911+
.help("destination type: exchange or queue")
1912+
.required(true),
1913+
)
1914+
.arg(
1915+
Arg::new("destination")
1916+
.long("destination")
1917+
.help("destination exchange/queue name")
1918+
.required(true),
1919+
)
1920+
.arg(
1921+
Arg::new("routing_key")
1922+
.long("routing-key")
1923+
.help("routing key")
1924+
.required(true),
1925+
)
1926+
.arg(
1927+
Arg::new("arguments")
1928+
.long("arguments")
1929+
.help("additional arguments")
1930+
.required(false)
1931+
.default_value("{}")
1932+
.value_parser(value_parser!(String)),
1933+
);
1934+
[bind_cmd, declare_cmd, delete_cmd, list_cmd, unbind_cmd]
1935+
.map(|cmd| cmd.infer_long_args(pre_flight_settings.infer_long_options))
1936+
}
18041937
fn export_subcommands(pre_flight_settings: PreFlightSettings) -> [Command; 1] {
18051938
let definitions = Command::new("definitions")
18061939
.about("Prefer 'definitions export'")

src/main.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,26 @@ fn dispatch_common_subcommand(
415415
let result = commands::export_cluster_wide_definitions(client, second_level_args);
416416
res_handler.no_output_on_success(result);
417417
}
418+
("exchanges", "bind") => {
419+
let result = commands::declare_binding(client, &vhost, second_level_args);
420+
res_handler.no_output_on_success(result);
421+
}
422+
("exchanges", "declare") => {
423+
let result = commands::declare_exchange(client, &vhost, second_level_args);
424+
res_handler.no_output_on_success(result);
425+
}
426+
("exchanges", "delete") => {
427+
let result = commands::delete_exchange(client, &vhost, second_level_args);
428+
res_handler.delete_operation_result(result);
429+
}
430+
("exchanges", "list") => {
431+
let result = commands::list_exchanges(client, &vhost);
432+
res_handler.tabular_result(result)
433+
}
434+
("exchanges", "unbind") => {
435+
let result = commands::delete_binding(client, &vhost, second_level_args);
436+
res_handler.no_output_on_success(result);
437+
}
418438
("feature_flags", "enable") => {
419439
let result = commands::enable_feature_flag(client, second_level_args);
420440
res_handler.no_output_on_success(result);

tests/bindings_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn test_list_bindings() -> Result<(), Box<dyn std::error::Error>> {
8484
);
8585

8686
// delete the queue from vhost 1
87-
run_succeeds(["-V", vh1, "delete", "queue", "--name", q1]);
87+
run_succeeds(["-V", vh1, "queues", "delete", "--name", q1]);
8888

8989
// these bindings were deleted with the queue
9090
run_succeeds(["-V", "bindings_vhost_1", "list", "bindings"]).stdout(

0 commit comments

Comments
 (0)