aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZachary Dremann <dremann@gmail.com>2014-06-13 22:27:51 -0400
committerZachary Dremann <dremann@gmail.com>2014-06-13 22:27:51 -0400
commitf6f56293cd795c74006f164a2e7c9a5ea9979f81 (patch)
treeb2195a4ea4ba64bb92e467453fa8ff06b6bef3ae
parent01d32fd1fe05d87e5814f2efd9171aa47ef7f664 (diff)
downloadrusty-irc-f6f56293cd795c74006f164a2e7c9a5ea9979f81.tar.gz
rusty-irc-f6f56293cd795c74006f164a2e7c9a5ea9979f81.zip
Add beginning of rusti example
-rw-r--r--examples/rusti.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/examples/rusti.rs b/examples/rusti.rs
new file mode 100644
index 0000000..05e7c3b
--- /dev/null
+++ b/examples/rusti.rs
@@ -0,0 +1,27 @@
+extern crate irc;
+extern crate getopts;
+
+use std::os;
+use std::io;
+
+use getopts::{getopts, opt, optflag, optflagmulti, optmulti, optopt, reqopt, usage};
+
+fn main() {
+ let opts = [
+ optmulti("c", "channel", "What channel should be joined", "CHANNEL"),
+ optflag("", "ignore-privmsg", "Ignore messages sent directly, only respond to those in a joinned channel"),
+ optopt("p", "port", "What port should be used to connect to server", "PORT"),
+ ];
+ let mut stderr = io::stderr();
+ let mut args = os::args();
+ let program = args.get(0);
+ let matches = match getopts(args.tail(), opts) {
+ Ok(m) => { m }
+ Err(e) => { let _ = writeln!(stderr, "{}", e.to_err_msg()); os::set_exit_status(1); return; }
+ };
+
+ let channels = matches.opt_strs("channel");
+ let port: u16 = from_str(matches.opt_str("port").unwrap_or("6667".to_string()).as_slice()).expect("Please pass a port number to -p or --port");
+ let ignore_privmsg = matches.opt_present("ignore-privmsg");
+ println!("{}, {}, {}", channels, port, ignore_privmsg);
+}