Skip to content

Commit 51d5d2f

Browse files
Refactor, reformat imports
1 parent c4a8c28 commit 51d5d2f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+233
-237
lines changed

src/cli.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use super::static_urls::*;
1818
use super::tanzu_cli::tanzu_subcommands;
1919
use crate::config::PreFlightSettings;
2020
use crate::output::TableStyle;
21-
use clap::{Arg, ArgAction, ArgGroup, Command, value_parser};
21+
use clap::{Arg, ArgAction, ArgGroup, Command, crate_version, value_parser};
2222
use rabbitmq_http_client::commons::{
2323
BindingDestinationType, ChannelUseMode, ExchangeType, MessageTransferAcknowledgementMode,
2424
PolicyTarget, QueueType, SupportedProtocol,
@@ -346,12 +346,12 @@ pub fn parser(pre_flight_settings: PreFlightSettings) -> Command {
346346
];
347347

348348
Command::new("rabbitmqadmin")
349-
.version(clap::crate_version!())
349+
.version(crate_version!())
350350
.author("The RabbitMQ Core Team")
351-
.about(format!("rabbitmqadmin gen 2, version: {}", clap::crate_version!()))
351+
.about(format!("rabbitmqadmin gen 2, version: {}", crate_version!()))
352352
.long_about(format!(
353353
"RabbitMQ CLI that uses the HTTP API. Version: {}",
354-
clap::crate_version!()
354+
crate_version!()
355355
))
356356
.infer_subcommands(pre_flight_settings.infer_subcommands)
357357
.infer_long_args(pre_flight_settings.infer_long_options)

src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use crate::constants::{
1919
use crate::output::TableStyle;
2020
use clap::ArgMatches;
2121
use serde::Deserialize;
22-
use std::collections::HashMap;
2322
use std::path::{Path, PathBuf};
23+
use std::{collections::HashMap, fs, io};
2424
use thiserror::Error;
2525
use url::Url;
2626

@@ -62,7 +62,7 @@ pub enum ConfigFileError {
6262
)]
6363
MissingConfigSection(String),
6464
#[error(transparent)]
65-
IoError(#[from] std::io::Error),
65+
IoError(#[from] io::Error),
6666
#[error("failed to deserialize the config file. Make sure it is valid TOML. Details: {0}")]
6767
DeserializationError(#[from] toml::de::Error),
6868
}
@@ -532,7 +532,7 @@ fn from_local_path(path: &Path) -> Result<ConfigurationMap<'_>, ConfigFileError>
532532
}
533533

534534
fn read_from_local_path(path: &PathBuf) -> Result<ConfigurationMap<'_>, ConfigFileError> {
535-
let contents = std::fs::read_to_string(path)?;
535+
let contents = fs::read_to_string(path)?;
536536
toml::from_str(&contents).map_err(ConfigFileError::from)
537537
}
538538

src/errors.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use reqwest::{
1818
StatusCode,
1919
header::{HeaderMap, InvalidHeaderValue},
2020
};
21+
use std::io;
2122
use url::Url;
2223

2324
#[derive(thiserror::Error, Debug)]
@@ -39,7 +40,7 @@ pub enum CommandRunError {
3940
cause: rustls::pki_types::pem::Error,
4041
},
4142
#[error("Run into an I/O error when loading a file: {0}")]
42-
IoError(std::io::Error),
43+
IoError(io::Error),
4344
#[error(
4445
"Local TLS certificate file at {local_path} does not exist, cannot be read or passed as a PEM file: {cause}"
4546
)]
@@ -103,8 +104,8 @@ pub enum CommandRunError {
103104
Other,
104105
}
105106

106-
impl From<std::io::Error> for CommandRunError {
107-
fn from(value: std::io::Error) -> Self {
107+
impl From<io::Error> for CommandRunError {
108+
fn from(value: io::Error) -> Self {
108109
CommandRunError::IoError(value)
109110
}
110111
}

src/main.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
#![allow(clippy::unnecessary_unwrap)]
1616
#![allow(clippy::collapsible_if)]
1717

18-
use clap::ArgMatches;
18+
use clap::{ArgMatches, crate_version};
1919
use errors::CommandRunError;
20-
use reqwest::Identity;
21-
use std::path::PathBuf;
20+
use reqwest::{Identity, tls::Version as TlsVersion};
21+
use std::path::{Path, PathBuf};
2222
use std::{fs, process};
2323
use sysexits::ExitCode;
2424

@@ -185,7 +185,7 @@ fn build_http_client(
185185
cli: &ArgMatches,
186186
common_settings: &SharedSettings,
187187
) -> Result<HTTPClient, CommandRunError> {
188-
let user_agent = format!("rabbitmqadmin-ng {}", clap::crate_version!());
188+
let user_agent = format!("rabbitmqadmin-ng {}", crate_version!());
189189
if should_use_tls(common_settings) {
190190
let _ = CryptoProvider::install_default(rustls::crypto::aws_lc_rs::default_provider());
191191

@@ -202,7 +202,7 @@ fn build_http_client(
202202
.use_rustls_tls()
203203
.tls_info(true)
204204
.tls_sni(true)
205-
.min_tls_version(reqwest::tls::Version::TLS_1_2)
205+
.min_tls_version(TlsVersion::TLS_1_2)
206206
.tls_built_in_native_certs(true)
207207
.tls_built_in_root_certs(true)
208208
.danger_accept_invalid_certs(disable_peer_verification)
@@ -315,7 +315,7 @@ fn read_pem_file(buf: &PathBuf, file_path: &str) -> Result<Vec<u8>, CommandRunEr
315315
}
316316

317317
fn validate_certificate_file(path: &str) -> Result<(), CommandRunError> {
318-
let path_buf = std::path::Path::new(path);
318+
let path_buf = Path::new(path);
319319

320320
if !path_buf.exists() {
321321
return Err(CommandRunError::CertificateFileNotFound {

src/output.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<'a> ResultHandler<'a> {
244244

245245
pub fn single_value_output_with_result<T: fmt::Display>(
246246
&mut self,
247-
result: Result<T, crate::errors::CommandRunError>,
247+
result: Result<T, CommandRunError>,
248248
) {
249249
match result {
250250
Ok(output) => {

src/pre_flight.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::env;
16+
1517
/// Represents the two modes of operation for the `rabbitmqadmin` CLI:
1618
/// interactive (driven by a human) and non-interactive (driven by automation tools).
1719
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -53,7 +55,7 @@ pub fn should_infer_long_options() -> bool {
5355
}
5456

5557
fn is_enabled_in_env(key: &str) -> bool {
56-
match std::env::var(key) {
58+
match env::var(key) {
5759
Ok(val) => val.to_lowercase().trim() == "true",
5860
Err(_) => false,
5961
}

src/tables.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rabbitmq_http_client::responses::{
1919
QuorumCriticalityCheckDetails, SchemaDefinitionSyncStatus,
2020
};
2121
use reqwest::StatusCode;
22-
use std::error::Error;
22+
use std::{error::Error, fmt};
2323
use tabled::settings::Panel;
2424
use tabled::{Table, Tabled};
2525
use url::Url;
@@ -57,7 +57,7 @@ struct OverviewRow<'a> {
5757
#[derive(Debug, Tabled)]
5858
struct RowOfTwo<'a, T>
5959
where
60-
T: ?Sized + std::fmt::Display,
60+
T: ?Sized + fmt::Display,
6161
{
6262
key: &'a str,
6363
value: &'a T,

tests/bindings_tests.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
// limitations under the License.
1414

1515
use predicates::prelude::*;
16+
use std::error::Error;
1617

1718
mod test_helpers;
1819
use crate::test_helpers::*;
1920

2021
#[test]
21-
fn test_list_bindings() -> Result<(), Box<dyn std::error::Error>> {
22+
fn test_list_bindings() -> Result<(), Box<dyn Error>> {
2223
let vh1 = "rabbitmqadmin.test_list_bindings_1";
2324
let vh2 = "rabbitmqadmin.test_list_bindings_2";
2425
let q1 = "new_queue_1";
@@ -103,7 +104,7 @@ fn test_list_bindings() -> Result<(), Box<dyn std::error::Error>> {
103104
}
104105

105106
#[test]
106-
fn test_bindings_list() -> Result<(), Box<dyn std::error::Error>> {
107+
fn test_bindings_list() -> Result<(), Box<dyn Error>> {
107108
let vh1 = "rabbitmqadmin.test_bindings_list_1";
108109
let vh2 = "rabbitmqadmin.test_bindings_list_2";
109110
let q1 = "new_queue_1";
@@ -202,7 +203,7 @@ fn test_bindings_list() -> Result<(), Box<dyn std::error::Error>> {
202203
}
203204

204205
#[test]
205-
fn test_bindings_delete_idempotently() -> Result<(), Box<dyn std::error::Error>> {
206+
fn test_bindings_delete_idempotently() -> Result<(), Box<dyn Error>> {
206207
let vh = "rabbitmqadmin.bindings.test1";
207208
let source_ex = "test_source_exchange";
208209
let dest_queue = "test_dest_queue";

tests/channels_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414

1515
mod test_helpers;
1616
use crate::test_helpers::*;
17-
17+
use std::error::Error;
1818
#[test]
19-
fn test_list_channels1() -> Result<(), Box<dyn std::error::Error>> {
19+
fn test_list_channels1() -> Result<(), Box<dyn Error>> {
2020
run_succeeds(["channels", "list"]);
2121

2222
Ok(())
2323
}
2424

2525
#[test]
26-
fn test_list_channels2() -> Result<(), Box<dyn std::error::Error>> {
26+
fn test_list_channels2() -> Result<(), Box<dyn Error>> {
2727
run_succeeds(["list", "channels"]);
2828

2929
Ok(())

tests/combined_integration_tests.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
use std::env;
15+
use std::error::Error;
1416
use std::path;
1517
use std::path::PathBuf;
1618

@@ -21,7 +23,7 @@ use crate::test_helpers::output_includes;
2123
use test_helpers::{run_fails, run_succeeds};
2224

2325
#[test]
24-
fn combined_integration_test1() -> Result<(), Box<dyn std::error::Error>> {
26+
fn combined_integration_test1() -> Result<(), Box<dyn Error>> {
2527
let vh = "rabbitmqadmin.combined_integration.test1";
2628
let config_path = path::absolute("./tests/fixtures/config_files/config_file1.conf")
2729
.expect("failed to compute an absolute version for a ./test/fixtures path");
@@ -46,7 +48,7 @@ fn combined_integration_test1() -> Result<(), Box<dyn std::error::Error>> {
4648
}
4749

4850
#[test]
49-
fn combined_integration_test2() -> Result<(), Box<dyn std::error::Error>> {
51+
fn combined_integration_test2() -> Result<(), Box<dyn Error>> {
5052
let vh = "rabbitmqadmin.combined_integration.test2";
5153

5254
// Uses a node alias that does not exist in the file
@@ -77,7 +79,7 @@ fn combined_integration_test2() -> Result<(), Box<dyn std::error::Error>> {
7779
}
7880

7981
#[test]
80-
fn combined_integration_test3() -> Result<(), Box<dyn std::error::Error>> {
82+
fn combined_integration_test3() -> Result<(), Box<dyn Error>> {
8183
let vh = "rabbitmqadmin.combined_integration.test3";
8284

8385
// Uses a node alias that does not exist in the file
@@ -97,7 +99,7 @@ fn combined_integration_test3() -> Result<(), Box<dyn std::error::Error>> {
9799
}
98100

99101
#[test]
100-
fn combined_integration_test4() -> Result<(), Box<dyn std::error::Error>> {
102+
fn combined_integration_test4() -> Result<(), Box<dyn Error>> {
101103
// This test uses administrative credentials to create a new user
102104
// and set up a topology using those new credentials
103105
let vh = "rabbitmqadmin.combined_integration.test4";
@@ -235,11 +237,11 @@ fn combined_integration_test4() -> Result<(), Box<dyn std::error::Error>> {
235237
// Implementation
236238
//
237239

238-
fn report_a_missing_config_file(config_path: PathBuf) -> Result<(), Box<dyn std::error::Error>> {
240+
fn report_a_missing_config_file(config_path: PathBuf) -> Result<(), Box<dyn Error>> {
239241
println!(
240242
"{} doesn't exist. Current working directory: {}",
241243
config_path.to_string_lossy(),
242-
std::env::current_dir()?.display()
244+
env::current_dir()?.display()
243245
);
244246
Ok(())
245247
}

0 commit comments

Comments
 (0)