From f6f56293cd795c74006f164a2e7c9a5ea9979f81 Mon Sep 17 00:00:00 2001 From: Zachary Dremann Date: Fri, 13 Jun 2014 22:27:51 -0400 Subject: Add beginning of rusti example --- examples/rusti.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 examples/rusti.rs 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); +} -- cgit v1.2.3