feat(engine): infrastructure

* 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
This commit is contained in:
Sebastian Thiel
2015-04-13 17:08:50 +02:00
parent b64722cca8
commit ca8e8c0622
4 changed files with 56 additions and 5 deletions

View File

@@ -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]):

View File

@@ -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>

View File

@@ -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)
@@ -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) => {
}
}
}

View File

@@ -0,0 +1,12 @@
#[derive(Debug)]
pub enum ArgumentError {
ConfigurationDirectoryInaccessible(String),
}
#[derive(Debug)]
pub struct InvalidOptionsError {
pub issues: Vec<ArgumentError>,
pub exit_code: i32,
}