Skip to content

Commit

Permalink
feat(CLI): --debug flag to output traffix
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Byron committed Apr 21, 2015
1 parent f7740ad commit 159c659
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
3 changes: 3 additions & 0 deletions etc/api/discovery/v1/discovery-api_overrides.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"no_auth": 1
}
1 change: 1 addition & 0 deletions etc/api/type-cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ cargo:
- docopt = "*"
- docopt_macros = "*"
- rustc-serialize = "*"
- yup-hyper-mock = "*"
- serde = ">= 0.3.0"
- serde_macros = "*"
4 changes: 3 additions & 1 deletion src/mako/api/lib/mbuild.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down Expand Up @@ -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"
%>
Expand All @@ -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(), ());
Expand Down
3 changes: 3 additions & 0 deletions src/mako/cli/lib/docopt.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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>
11 changes: 10 additions & 1 deletion src/mako/cli/lib/engine.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions src/mako/cli/main.rs.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 159c659

Please sign in to comment.