Skip to content

Commit 2fabea4

Browse files
euankLinuxMercedes
authored andcommitted
cargo fmt
1 parent 2a9f40e commit 2fabea4

1 file changed

Lines changed: 55 additions & 45 deletions

File tree

src/main.rs

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ extern crate clap;
1010
#[macro_use]
1111
extern crate log;
1212
extern crate env_logger;
13-
use log::LogLevelFilter;
1413
use env_logger::LogBuilder;
14+
use log::LogLevelFilter;
1515

1616
use std::convert::From;
1717

@@ -25,10 +25,9 @@ extern crate isatty;
2525
use isatty::stdout_isatty;
2626

2727
use std::io::prelude::*;
28+
use std::io::stdout;
2829
use std::io::BufReader;
2930
use std::io::Error as IoError;
30-
use std::io::stdout;
31-
3231

3332
/// Actions that threads can take
3433
#[derive(Debug)]
@@ -60,33 +59,31 @@ impl From<&'static str> for Action {
6059
}
6160
}
6261

63-
6462
fn main() {
6563
// Catch signals we expect to exit cleanly from
6664
// I don't think rust actually sends SIGPIPE, but we'll catch it anyway
6765
let signal = chan_signal::notify(&[Signal::INT, Signal::TERM, Signal::PIPE]);
6866

69-
7067
// Parse args
7168
let matches = clap_app!
72-
(hashpipe =>
73-
(version: crate_version!())
74-
(author: crate_authors!())
75-
(about: "#|: Pipes data to and from an IRC connection")
76-
(@arg server: -s --server +required +takes_value "IRC server to connect to")
77-
(@arg port: -p --port +takes_value "Port to use (default: 6667, or 6697 with SSL)")
78-
(@arg no_ssl: -d long("--no-ssl") "Disable SSL encryption")
79-
(@arg nick: -n --nick +takes_value "Nickname to use (default: hashpipe)")
80-
(@arg channels: -c --channels +takes_value "Channel(s) to speak in \
81-
(defalt: #hashpipe, or nothing if using raw input)")
82-
// NOTE: long() is a required workaround for parsing long options with
83-
// hyphens; see https://github.com/kbknapp/clap-rs/issues/321
84-
(@arg raw_out: -o long("--raw-out") "Echo everything from the IRC server directly")
85-
(@arg raw_in: -i long("--raw-in") "Interpret STDIN as raw IRC commands")
86-
(@arg v: -v +multiple "Verbosity (1 for info, 2 for debug)")
87-
(@arg quiet: -q "Only print errors (overrides -v; overridden by raw output)")
88-
)
89-
.get_matches();
69+
(hashpipe =>
70+
(version: crate_version!())
71+
(author: crate_authors!())
72+
(about: "#|: Pipes data to and from an IRC connection")
73+
(@arg server: -s --server +required +takes_value "IRC server to connect to")
74+
(@arg port: -p --port +takes_value "Port to use (default: 6667, or 6697 with SSL)")
75+
(@arg no_ssl: -d long("--no-ssl") "Disable SSL encryption")
76+
(@arg nick: -n --nick +takes_value "Nickname to use (default: hashpipe)")
77+
(@arg channels: -c --channels +takes_value "Channel(s) to speak in \
78+
(defalt: #hashpipe, or nothing if using raw input)")
79+
// NOTE: long() is a required workaround for parsing long options with
80+
// hyphens; see https://github.com/kbknapp/clap-rs/issues/321
81+
(@arg raw_out: -o long("--raw-out") "Echo everything from the IRC server directly")
82+
(@arg raw_in: -i long("--raw-in") "Interpret STDIN as raw IRC commands")
83+
(@arg v: -v +multiple "Verbosity (1 for info, 2 for debug)")
84+
(@arg quiet: -q "Only print errors (overrides -v; overridden by raw output)")
85+
)
86+
.get_matches();
9087

9188
let raw_out = matches.is_present("raw_out");
9289
let raw_in = matches.is_present("raw_in");
@@ -98,9 +95,11 @@ fn main() {
9895
let port = matches.value_of("port").and_then(|p| p.parse().ok());
9996

10097
// Filter empty strings from channel names
101-
let sanitized_chans: Vec<String> = matches.value_of("channels")
98+
let sanitized_chans: Vec<String> = matches
99+
.value_of("channels")
102100
.map(|chans| {
103-
chans.split(',')
101+
chans
102+
.split(',')
104103
.filter(|x| *x != "")
105104
.map(|x| x.to_string())
106105
.collect()
@@ -113,7 +112,6 @@ fn main() {
113112
vec!["#hashpipe".to_string()]
114113
};
115114

116-
117115
// Set up logger
118116
let mut builder = LogBuilder::new();
119117
let level = match (matches.occurrences_of("v"), quiet) {
@@ -125,7 +123,6 @@ fn main() {
125123
builder.filter(None, level);
126124
builder.init().unwrap();
127125

128-
129126
// Set up IRC server
130127
let cfg = Config {
131128
nickname: Some(nick),
@@ -235,39 +232,51 @@ fn main() {
235232

236233
/// Manage IRC connection; read and print messages; signal on JOIN or QUIT
237234
fn run_irc(client: IrcClient, raw: bool, quiet: bool, sjoin: chan::Sender<Action>) {
238-
client.identify().unwrap_or_else(|err| sjoin.send(From::from(err)));
235+
client
236+
.identify()
237+
.unwrap_or_else(|err| sjoin.send(From::from(err)));
239238

240239
let res = client.for_each_incoming(|msg| {
241240
if raw {
242241
print!("{}", msg);
243-
stdout().flush().unwrap_or_else(|err| sjoin.send(From::from(err)));
242+
stdout()
243+
.flush()
244+
.unwrap_or_else(|err| sjoin.send(From::from(err)));
244245
}
245246
match msg.command {
246247
Command::JOIN(ref _channel, ref _a, ref _b) => sjoin.send(Action::Join),
247248
Command::PRIVMSG(ref target, ref what_was_said) => {
248249
if !raw && !quiet {
249-
println!("{}->{}: {}",
250-
msg.source_nickname().unwrap_or("* "),
251-
target,
252-
what_was_said);
253-
stdout().flush().unwrap_or_else(|err| sjoin.send(From::from(err)));
250+
println!(
251+
"{}->{}: {}",
252+
msg.source_nickname().unwrap_or("* "),
253+
target,
254+
what_was_said
255+
);
256+
stdout()
257+
.flush()
258+
.unwrap_or_else(|err| sjoin.send(From::from(err)));
254259
}
255260
}
256261
Command::NOTICE(ref target, ref what_was_said) => {
257262
if !raw && !quiet {
258-
println!("{}->{}: {}",
259-
msg.source_nickname().unwrap_or("* "),
260-
target,
261-
what_was_said);
262-
stdout().flush().unwrap_or_else(|err| sjoin.send(From::from(err)));
263+
println!(
264+
"{}->{}: {}",
265+
msg.source_nickname().unwrap_or("* "),
266+
target,
267+
what_was_said
268+
);
269+
stdout()
270+
.flush()
271+
.unwrap_or_else(|err| sjoin.send(From::from(err)));
263272
}
264273
}
265274
Command::QUIT(ref _quitmessage) => sjoin.send(Action::Quit),
266275
Command::Response(ref response, ref command, ref err) => {
267276
// Handle un-joinable channels
268277
let the_problem = command.get(1).map_or("", |s| &*s);
269-
let errmsg = the_problem.to_string() + ": " +
270-
&err.clone().unwrap_or("".to_string());
278+
let errmsg =
279+
the_problem.to_string() + ": " + &err.clone().unwrap_or("".to_string());
271280

272281
match *response {
273282
Response::ERR_CHANNELISFULL => sjoin.send(Action::JoinFail(errmsg)),
@@ -300,14 +309,15 @@ fn run_io(client: IrcClient, channels: Vec<String>, raw: bool, sdone: chan::Send
300309
if raw {
301310
let raw_line = ln + "\r\n"; // IRC line terminator
302311
match Message::from_str(&raw_line) {
303-
Ok(msg) => {
304-
client.send(msg).unwrap_or_else(|err| sdone.send(From::from(err)))
305-
}
312+
Ok(msg) => client
313+
.send(msg)
314+
.unwrap_or_else(|err| sdone.send(From::from(err))),
306315
Err(err) => sdone.send(From::from(err)),
307316
}
308317
} else {
309318
for channel in &channels {
310-
client.send_privmsg(&channel, &ln)
319+
client
320+
.send_privmsg(&channel, &ln)
311321
.unwrap_or_else(|err| sdone.send(From::from(err)));
312322
}
313323
}

0 commit comments

Comments
 (0)