Skip to content

Commit

Permalink
feat(engine): infrastructure
Browse files Browse the repository at this point in the history
* allow usage of cmn.rs for common types (like Error types)
* instantiate an engine and handle errors, in an initial quick and dirty
  way.

 Fixes #52
  • Loading branch information
Byron committed Apr 13, 2015
1 parent b64722c commit ca8e8c0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/mako/cli/lib/docopt.mako
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
upload_protocols_used = set()
output_used = False
%>\
docopt!(Args derive Debug, "
docopt!(Options derive Debug, "
Usage:
% for resource in sorted(c.rta_map.keys()):
% for method in sorted(c.rta_map[resource]):
Expand Down
24 changes: 24 additions & 0 deletions src/mako/cli/lib/engine.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<%namespace name="util" file="../../lib/util.mako"/>\
<%!
from cli import (mangle_subcommand, new_method_context, PARAM_FLAG, STRUCT_FLAG, UPLOAD_FLAG, OUTPUT_FLAG, VALUE_ARG,
CONFIG_DIR, SCOPE_FLAG, is_request_value_property, FIELD_SEP, docopt_mode, FILE_ARG, MIME_ARG, OUT_ARG)
v_arg = '<%s>' % VALUE_ARG
%>\
<%def name="new(c)">\
mod cmn;
use cmn::{InvalidOptionsError, ArgumentError};
struct Engine {
opts: Options,
}
impl Engine {
fn new(options: Options) -> Result<Engine, InvalidOptionsError> {
Ok(Engine {
opts: options,
})
}
}
</%def>
23 changes: 19 additions & 4 deletions src/mako/cli/main.rs.mako
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%namespace name="docopt" file="lib/docopt.mako"/>\
<%namespace name="engine" file="lib/engine.mako"/>\
<%namespace name="util" file="../lib/util.mako"/>\
<%
from util import (new_context, rust_comment)
Expand All @@ -9,16 +10,30 @@
<%block filter="rust_comment">\
<%util:gen_info source="${self.uri}" />\
</%block>
#![feature(plugin)]
#![feature(plugin, exit_status)]
#![plugin(docopt_macros)]

extern crate docopt;
extern crate rustc_serialize;

use std::io;
use std::env;
use std::io::Write;

${docopt.new(c)}\

${engine.new(c)}\

fn main() {
let args: Args = Args::docopt().decode().unwrap_or_else(|e| e.exit());
println!("{:?}", args);
println!("Hello, ${id} !");
let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit());
println!("{:?}", opts);
match Engine::new(opts) {
Err(e) => {
write!(io::stderr(), "{:?}", e).ok();
env::set_exit_status(e.exit_code);
},
Ok(mut engine) => {

}
}
}
12 changes: 12 additions & 0 deletions src/rust/cli/cmn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


#[derive(Debug)]
pub enum ArgumentError {
ConfigurationDirectoryInaccessible(String),
}

#[derive(Debug)]
pub struct InvalidOptionsError {
pub issues: Vec<ArgumentError>,
pub exit_code: i32,
}

0 comments on commit ca8e8c0

Please sign in to comment.