Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: fix clippy warnings #18

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ fn connect(host: &str, params: &HostParams) {
Some(h) => h,
None => host,
};
let port = match params.port {
None => 22,
Some(p) => p,
};
let port = params.port.unwrap_or(22);
let host = match host.contains(':') {
true => host.to_string(),
false => format!("{}:{}", host, port),
Expand Down
18 changes: 12 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,26 @@ mod test {
fn should_query_ssh_config() {
let mut config = SshConfig::default();
// add config
let mut params1 = HostParams::default();
params1.bind_address = Some(String::from("0.0.0.0"));
let mut params1 = HostParams {
bind_address: Some(String::from("0.0.0.0")),
..Default::default()
};
config.hosts.push(Host::new(
vec![HostClause::new(String::from("192.168.*.*"), false)],
params1.clone(),
));
let mut params2 = HostParams::default();
params2.bind_interface = Some(String::from("tun0"));
let params2 = HostParams {
bind_interface: Some(String::from("tun0")),
..Default::default()
};
config.hosts.push(Host::new(
vec![HostClause::new(String::from("192.168.10.*"), false)],
params2.clone(),
));
let mut params3 = HostParams::default();
params3.host_name = Some(String::from("172.26.104.4"));
let params3 = HostParams {
host_name: Some(String::from("172.26.104.4")),
..Default::default()
};
config.hosts.push(Host::new(
vec![
HostClause::new(String::from("172.26.*.*"), false),
Expand Down
50 changes: 25 additions & 25 deletions src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,31 +246,31 @@ mod test {
#[test]
fn should_merge_params() {
let mut params = HostParams::default();
let mut b = HostParams::default();
b.bind_address = Some(String::from("pippo"));
b.bind_interface = Some(String::from("tun0"));
b.ca_signature_algorithms = Some(vec![]);
b.certificate_file = Some(PathBuf::default());
b.ciphers = Some(vec![]);
b.compression = Some(true);
b.connect_timeout = Some(Duration::from_secs(1));
b.connection_attempts = Some(3);
b.host_key_algorithms = Some(vec![]);
b.host_name = Some(String::from("192.168.1.2"));
b.identity_file = Some(vec![PathBuf::default()]);
b.ignore_unknown = Some(vec![]);
b.kex_algorithms = Some(vec![]);
b.mac = Some(vec![]);
b.port = Some(22);
b.pubkey_accepted_algorithms = Some(vec![]);
b.pubkey_authentication = Some(true);
b.remote_forward = Some(32);
b.server_alive_interval = Some(Duration::from_secs(10));
#[cfg(target_os = "macos")]
{
b.use_keychain = Some(true);
}
b.tcp_keep_alive = Some(true);
let mut b = HostParams {
bind_address: Some(String::from("pippo")),
bind_interface: Some(String::from("tun0")),
ca_signature_algorithms: Some(vec![]),
certificate_file: Some(PathBuf::default()),
ciphers: Some(vec![]),
compression: Some(true),
connect_timeout: Some(Duration::from_secs(1)),
connection_attempts: Some(3),
host_key_algorithms: Some(vec![]),
host_name: Some(String::from("192.168.1.2")),
identity_file: Some(vec![PathBuf::default()]),
ignore_unknown: Some(vec![]),
kex_algorithms: Some(vec![]),
mac: Some(vec![]),
port: Some(22),
pubkey_accepted_algorithms: Some(vec![]),
pubkey_authentication: Some(true),
remote_forward: Some(32),
server_alive_interval: Some(Duration::from_secs(10)),
#[cfg(target_os = "macos")]
use_keychain: Some(true),
tcp_keep_alive: Some(true),
..Default::default()
};
params.merge(&b);
assert!(params.bind_address.is_some());
assert!(params.bind_interface.is_some());
Expand Down
10 changes: 5 additions & 5 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl SshConfigParser {

/// parse boolean value
fn parse_boolean(args: Vec<String>) -> SshParserResult<bool> {
match args.get(0).map(|x| x.as_str()) {
match args.first().map(|x| x.as_str()) {
Some("yes") => Ok(true),
Some("no") => Ok(false),
Some(_) => Err(SshParserError::ExpectedBoolean),
Expand All @@ -315,7 +315,7 @@ impl SshConfigParser {
/// Parse comma separated list arguments
fn parse_comma_separated_list(args: Vec<String>) -> SshParserResult<Vec<String>> {
match args
.get(0)
.first()
.map(|x| x.split(',').map(|x| x.to_string()).collect())
{
Some(args) => Ok(args),
Expand Down Expand Up @@ -360,7 +360,7 @@ impl SshConfigParser {

/// Parse path argument
fn parse_path(args: Vec<String>) -> SshParserResult<PathBuf> {
if let Some(s) = args.get(0) {
if let Some(s) = args.first() {
Self::parse_path_arg(s)
} else {
Err(SshParserError::MissingArgument)
Expand All @@ -384,7 +384,7 @@ impl SshConfigParser {

/// Parse port number argument
fn parse_port(args: Vec<String>) -> SshParserResult<u16> {
match args.get(0).map(|x| u16::from_str(x)) {
match args.first().map(|x| u16::from_str(x)) {
Some(Ok(val)) => Ok(val),
Some(Err(_)) => Err(SshParserError::ExpectedPort),
None => Err(SshParserError::MissingArgument),
Expand All @@ -402,7 +402,7 @@ impl SshConfigParser {

/// Parse unsigned argument
fn parse_unsigned(args: Vec<String>) -> SshParserResult<usize> {
match args.get(0).map(|x| usize::from_str(x)) {
match args.first().map(|x| usize::from_str(x)) {
Some(Ok(val)) => Ok(val),
Some(Err(_)) => Err(SshParserError::ExpectedUnsigned),
None => Err(SshParserError::MissingArgument),
Expand Down
Loading