feat(CLI): --debug flag to output traffix

* If `--debug` is set, we will output all server communication to
  stderr. That way, we can compare our requests to what is expected by
  ush based on official docs.
* `discovery` now doesn't use the API key anymore - this is specified
   using a custom override.

Nice, we are totally ready to test and fix all API features.

Related to #70
This commit is contained in:
Sebastian Thiel
2015-04-21 12:03:58 +02:00
parent f7740ad149
commit 159c65916f
6 changed files with 24 additions and 4 deletions

View File

@@ -0,0 +1,3 @@
{
"no_auth": 1
}

View File

@@ -29,5 +29,6 @@ cargo:
- docopt = "*"
- docopt_macros = "*"
- rustc-serialize = "*"
- yup-hyper-mock = "*"
- serde = ">= 0.3.0"
- serde_macros = "*"

View File

@@ -325,7 +325,7 @@ ${capture(lib.test_hub, hub_type_name, comments=show_all) | hide_filter}
// As the method needs a request, you would usually fill it with the desired information
// into the respective structure. Some of the parts shown here might not be applicable !
// ${random_value_warning}
let mut ${rb_name}: ${request_value_type} = Default::default();
let mut ${rb_name} = ${request_value_type}::default();
% for spn, sp in request_value.get('properties', dict()).iteritems():
% if parts is not None and spn not in parts:
<% continue %>
@@ -579,6 +579,7 @@ else {
let mut url = "${baseUrl}${m.path}".to_string();
% endif
% if not default_scope:
% if no_auth is UNDEFINED:
<%
assert 'key' in parameters, "Expected 'key' parameter if there are no scopes"
%>
@@ -593,6 +594,7 @@ else {
return Err(Error::MissingAPIKey)
}
}
% endif
% else:
if self.${api.properties.scopes}.len() == 0 {
self.${api.properties.scopes}.insert(${scope_url_to_variant(name, default_scope, fully_qualified=True)}.as_ref().to_string(), ());

View File

@@ -66,5 +66,8 @@ Configuration:
A directory into which we will store our persistent data. Defaults to a user-writable
directory that we will create during the first invocation.
[default: ${CONFIG_DIR}]
--debug
Output all server communication to standard error. `tx` and `rx` are placed into
the same stream.
");
</%def>

View File

@@ -112,9 +112,18 @@ self.opt.${cmd_ident(method)} {
program_name: "${util.program_name()}",
db_dir: config_dir.clone(),
}, None);
let client =
if opt.flag_debug {
hyper::Client::with_connector(mock::TeeConnector {
connector: hyper::net::HttpConnector(None)
})
} else {
hyper::Client::new()
};
let engine = Engine {
opt: opt,
hub: ${hub_type_name}::new(hyper::Client::new(), auth),
hub: ${hub_type_name}::new(client, auth),
};
match engine._doit(true) {

View File

@@ -16,6 +16,7 @@
extern crate docopt;
extern crate yup_oauth2 as oauth2;
extern crate yup_hyper_mock as mock;
extern crate rustc_serialize;
extern crate serde;
extern crate hyper;
@@ -33,12 +34,13 @@ fn main() {
let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit());
match Engine::new(opts) {
Err(err) => {
write!(io::stderr(), "{}", err).ok();
writeln!(io::stderr(), "{}", err).ok();
env::set_exit_status(err.exit_code);
},
Ok(engine) => {
if let Some(err) = engine.doit() {
write!(io::stderr(), "{}", err).ok();
writeln!(io::stderr(), "{:?}", err).ok();
writeln!(io::stderr(), "{}", err).ok();
env::set_exit_status(1);
}
}