Skip to content

Instantly share code, notes, and snippets.

@Khady
Created February 27, 2013 15:30
Show Gist options
  • Save Khady/5048759 to your computer and use it in GitHub Desktop.
Save Khady/5048759 to your computer and use it in GitHub Desktop.
extern mod pcre;
extern mod std;
use std::getopts::*;
use std::time::*;
use std::map::HashMap;
use std::map::Map;
use std::map::;
// struct context {
// // year: ~str,
// // organization: ~str,
// // project: ~str
// }
fn print_usage(program: &str, _opts: &[std::getopts::Opt]) {
io::println(fmt!("Usage: %s [options]", program));
io::println("-o\t\tOutput");
io::println("-h --help\tUsage");
}
// fn make_absolute(p: &Path) -> Path
fn get_license(args: Option<~str>) -> ~str {
match args {
Some(move x) => x.to_lower(),
None => ~"bsd3"
}
}
fn get_proj(args: Option<~str>) -> ~str {
match args {
Some(move x) => x,
None => {
match os::getcwd().filename() {
Some(dir) => dir,
None => ~"project"
}
}
}
}
fn get_org(args: Option<~str>) -> ~str {
match args {
Some(move x) => x,
None => {
match os::getenv("USER") {
Some(dir) => dir,
None => ~"organization"
}
}
}
}
fn get_year(args: Option<~str>) -> ~str {
match args {
Some(move x) => x,
None => {
let time = now();
time.strftime("%Y")
}
}
}
fn load_file_template(file: ~str) -> ~str {
io::println(file);
// check if file exist. If true, replace with a regexp. Else raise an error
~"error"
}
fn main() {
let args = os::args();
let program = copy args[0];
let opts = ~[
optflag("h"),
optflag("help"),
optopt("year"),
optopt("proj"),
optopt("org"),
optopt("license")
];
let matches = match getopts(vec::tail(args), opts) {
result::Ok(m) => { m }
result::Err(f) => { fail fail_str(f) }
};
if opt_present(&matches, "h") || opt_present(&matches, "help") {
print_usage(program, opts);
return;
}
let year = opt_maybe_str(&matches, "year");
let proj = opt_maybe_str(&matches, "proj");
let org = opt_maybe_str(&matches, "org");
let license = opt_maybe_str(&matches, "license");
// io::println(get_year(year));
// io::println(get_proj(proj));
// io::println(get_org(org));
// io::println(get_license(license));
let context: HashMap<~str, ~str> = HashMap::<~str, ~str>();
context.insert(~"year", get_year(year));
context.insert(~"proj", get_proj(proj));
context.insert(~"org", get_org(org));
context.insert(~"license", get_license(license));
let template = load_file_template(~"template-" + context.get(~"license") + ~".txt");
io::println(template);
// let content = generate_license(template);
}
% rustc licenseRs.rs
licenseRs.rs:83:32: 83:41 warning: instantiating copy type parameter with a not implicitly copyable type
licenseRs.rs:83 let matches = match getopts(vec::tail(args), opts) {
^~~~~~~~~
licenseRs.rs:101:39: 101:60 warning: instantiating copy type parameter with a not implicitly copyable type
licenseRs.rs:101 let context: HashMap<~str, ~str> = HashMap::<~str, ~str>();
^~~~~~~~~~~~~~~~~~~~~
licenseRs.rs:102:4: 102:44 warning: instantiating copy type parameter with a not implicitly copyable type
licenseRs.rs:102 context.insert(~"year", get_year(year));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
licenseRs.rs:102:4: 102:44 warning: instantiating copy type parameter with a not implicitly copyable type
licenseRs.rs:102 context.insert(~"year", get_year(year));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
licenseRs.rs:103:4: 103:44 warning: instantiating copy type parameter with a not implicitly copyable type
licenseRs.rs:103 context.insert(~"proj", get_proj(proj));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
licenseRs.rs:103:4: 103:44 warning: instantiating copy type parameter with a not implicitly copyable type
licenseRs.rs:103 context.insert(~"proj", get_proj(proj));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
licenseRs.rs:104:4: 104:41 warning: instantiating copy type parameter with a not implicitly copyable type
licenseRs.rs:104 context.insert(~"org", get_org(org));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
licenseRs.rs:104:4: 104:41 warning: instantiating copy type parameter with a not implicitly copyable type
licenseRs.rs:104 context.insert(~"org", get_org(org));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
licenseRs.rs:105:4: 105:53 warning: instantiating copy type parameter with a not implicitly copyable type
licenseRs.rs:105 context.insert(~"license", get_license(license));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
licenseRs.rs:105:4: 105:53 warning: instantiating copy type parameter with a not implicitly copyable type
licenseRs.rs:105 context.insert(~"license", get_license(license));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
licenseRs.rs:107:53: 107:78 warning: instantiating copy type parameter with a not implicitly copyable type
licenseRs.rs:107 let template = load_file_template(~"template-" + context.get(~"license") + ~".txt");
^~~~~~~~~~~~~~~~~~~~~~~~~
licenseRs.rs:107:53: 107:78 warning: instantiating copy type parameter with a not implicitly copyable type
licenseRs.rs:107 let template = load_file_template(~"template-" + context.get(~"license") + ~".txt");
^~~~~~~~~~~~~~~~~~~~~~~~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment