Skip to content

Commit 159c659

Browse files
committed
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
1 parent f7740ad commit 159c659

6 files changed

Lines changed: 24 additions & 4 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"no_auth": 1
3+
}

etc/api/type-cli.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ cargo:
2929
- docopt = "*"
3030
- docopt_macros = "*"
3131
- rustc-serialize = "*"
32+
- yup-hyper-mock = "*"
3233
- serde = ">= 0.3.0"
3334
- serde_macros = "*"

src/mako/api/lib/mbuild.mako

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ ${capture(lib.test_hub, hub_type_name, comments=show_all) | hide_filter}
325325
// As the method needs a request, you would usually fill it with the desired information
326326
// into the respective structure. Some of the parts shown here might not be applicable !
327327
// ${random_value_warning}
328-
let mut ${rb_name}: ${request_value_type} = Default::default();
328+
let mut ${rb_name} = ${request_value_type}::default();
329329
% for spn, sp in request_value.get('properties', dict()).iteritems():
330330
% if parts is not None and spn not in parts:
331331
<% continue %>
@@ -579,6 +579,7 @@ else {
579579
let mut url = "${baseUrl}${m.path}".to_string();
580580
% endif
581581
% if not default_scope:
582+
% if no_auth is UNDEFINED:
582583
<%
583584
assert 'key' in parameters, "Expected 'key' parameter if there are no scopes"
584585
%>
@@ -593,6 +594,7 @@ else {
593594
return Err(Error::MissingAPIKey)
594595
}
595596
}
597+
% endif
596598
% else:
597599
if self.${api.properties.scopes}.len() == 0 {
598600
self.${api.properties.scopes}.insert(${scope_url_to_variant(name, default_scope, fully_qualified=True)}.as_ref().to_string(), ());

src/mako/cli/lib/docopt.mako

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,8 @@ Configuration:
6666
A directory into which we will store our persistent data. Defaults to a user-writable
6767
directory that we will create during the first invocation.
6868
[default: ${CONFIG_DIR}]
69+
--debug
70+
Output all server communication to standard error. `tx` and `rx` are placed into
71+
the same stream.
6972
");
7073
</%def>

src/mako/cli/lib/engine.mako

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,18 @@ self.opt.${cmd_ident(method)} {
112112
program_name: "${util.program_name()}",
113113
db_dir: config_dir.clone(),
114114
}, None);
115+
116+
let client =
117+
if opt.flag_debug {
118+
hyper::Client::with_connector(mock::TeeConnector {
119+
connector: hyper::net::HttpConnector(None)
120+
})
121+
} else {
122+
hyper::Client::new()
123+
};
115124
let engine = Engine {
116125
opt: opt,
117-
hub: ${hub_type_name}::new(hyper::Client::new(), auth),
126+
hub: ${hub_type_name}::new(client, auth),
118127
};
119128
120129
match engine._doit(true) {

src/mako/cli/main.rs.mako

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
extern crate docopt;
1818
extern crate yup_oauth2 as oauth2;
19+
extern crate yup_hyper_mock as mock;
1920
extern crate rustc_serialize;
2021
extern crate serde;
2122
extern crate hyper;
@@ -33,12 +34,13 @@ fn main() {
3334
let opts: Options = Options::docopt().decode().unwrap_or_else(|e| e.exit());
3435
match Engine::new(opts) {
3536
Err(err) => {
36-
write!(io::stderr(), "{}", err).ok();
37+
writeln!(io::stderr(), "{}", err).ok();
3738
env::set_exit_status(err.exit_code);
3839
},
3940
Ok(engine) => {
4041
if let Some(err) = engine.doit() {
41-
write!(io::stderr(), "{}", err).ok();
42+
writeln!(io::stderr(), "{:?}", err).ok();
43+
writeln!(io::stderr(), "{}", err).ok();
4244
env::set_exit_status(1);
4345
}
4446
}

0 commit comments

Comments
 (0)