Remove support for debug logging of CLI programs

The needed feature was removed from yup-hyper-mock, and if needed
it can certainly be re-implemented.
This commit is contained in:
Sebastian Thiel
2021-04-01 16:37:53 +08:00
parent 112ef3f3ac
commit 0bf46b95f3
7 changed files with 6 additions and 120 deletions

View File

@@ -26,7 +26,6 @@ path = "src/main.rs"
% endif
[dependencies]
hyper = "^ 0.14"
hyper-rustls = "^0.22"
## Must match the one hyper uses, otherwise there are duplicate similarly named `Mime` structs
mime = "^ 0.2.0"
@@ -34,7 +33,6 @@ serde = "^ 1.0"
serde_json = "^ 1.0"
serde_derive = "^ 1.0"
yup-oauth2 = "^ 5.0"
tokio = "^ 1.0"
itertools = "^ 0.10"
% for dep in cargo.get('dependencies', list()):
${dep}

View File

@@ -1,6 +1,6 @@
<%
from util import (markdown_comment, new_context)
from cli import (CONFIG_DIR, CONFIG_DIR_FLAG, SCOPE_FLAG, application_secret_path, DEBUG_FLAG, DEBUG_AUTH_FLAG)
from cli import (CONFIG_DIR, CONFIG_DIR_FLAG, SCOPE_FLAG, application_secret_path, DEBUG_FLAG)
c = new_context(schemas, resources, context.get('methods'))
%>\
@@ -88,10 +88,7 @@ Even though the CLI does its best to provide usable error messages, sometimes it
what exactly led to a particular issue. This is done by allowing all client-server communication to be
output to standard error *as-is*.
The `--${DEBUG_FLAG}` flag will print all client-server communication to standard error, whereas the `--${DEBUG_AUTH_FLAG}` flag
will cause all communication related to authentication to standard error.
If the `--${DEBUG_FLAG}` flag is set, error-results will be debug-printed, possibly yielding more information about the
issue at hand.
The `--${DEBUG_FLAG}` flag will print errors using the `Debug` representation to standard error.
You may consider redirecting standard error into a file for ease of use, e.g. `${util.program_name()} --${DEBUG_FLAG} <resource> <method> [options] 2>debug.txt`.

View File

@@ -5,7 +5,7 @@
from util import (put_and, supports_scopes, api_index, indent_by, enclose_in, put_and, escape_rust_string)
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,
CONFIG_DIR_FLAG, KEY_VALUE_ARG, to_docopt_arg, DEBUG_FLAG, DEBUG_AUTH_FLAG, MODE_ARG, SCOPE_ARG,
CONFIG_DIR_FLAG, KEY_VALUE_ARG, to_docopt_arg, DEBUG_FLAG, MODE_ARG, SCOPE_ARG,
CONFIG_DIR_ARG, FILE_FLAG, MIME_FLAG, subcommand_md_filename)
def rust_boolean(v):
@@ -71,12 +71,6 @@ 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_FLAG}
Output all server communication to standard error. `tx` and `rx` are placed
into the same stream.
--${DEBUG_AUTH_FLAG}
Output all communication related to authentication to standard error. `tx`
and `rx` are placed into the same stream.
</%def>
@@ -114,16 +108,7 @@ Configuration:
global_args.append((
DEBUG_FLAG,
"Output all server communication to standard error. `tx` and `rx` are placed "
"into the same stream.",
None,
False,
))
global_args.append((
DEBUG_AUTH_FLAG,
"Output all communication related to authentication to standard error. `tx` "
"and `rx` are placed into the same stream.",
"Debug print all errors",
None,
False,
))

View File

@@ -7,7 +7,7 @@
CONFIG_DIR, SCOPE_FLAG, is_request_value_property, FIELD_SEP, docopt_mode, FILE_ARG, MIME_ARG, OUT_ARG,
call_method_ident, POD_TYPES, opt_value, ident, JSON_TYPE_VALUE_MAP,
KEY_VALUE_ARG, to_cli_schema, SchemaEntry, CTYPE_POD, actual_json_type, CTYPE_MAP, CTYPE_ARRAY,
application_secret_path, DEBUG_FLAG, DEBUG_AUTH_FLAG, CONFIG_DIR_FLAG, req_value, MODE_ARG,
application_secret_path, CONFIG_DIR_FLAG, req_value, MODE_ARG,
opt_values, SCOPE_ARG, CONFIG_DIR_ARG, DEFAULT_MIME, field_vec, comma_sep_fields, JSON_TYPE_TO_ENUM_MAP,
CTYPE_TO_ENUM_MAP)
@@ -122,8 +122,7 @@ impl<'n> Engine<'n> {
yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
).persist_tokens_to_disk(format!("{}/${util.program_name()}", config_dir)).build().await.unwrap();
let client =
${self._debug_client(DEBUG_FLAG) | indent_all_but_first_by(3)};
let client = hyper::Client::builder().build(hyper_rustls::HttpsConnector::with_native_roots());
<% gpm = gen_global_parameter_names(parameters) %>\
let engine = Engine {
opt: opt,
@@ -152,16 +151,6 @@ impl<'n> Engine<'n> {
}
</%def>
<%def name="_debug_client(flag_name)" buffered="True">\
if opt.is_present("${flag_name}") {
hyper::Client::with_connector(mock::TeeConnector {
connector: hyper::net::HttpsConnector::new(hyper_rustls::TlsClient::new())
})
} else {
hyper::Client::with_connector(hyper::net::HttpsConnector::new(hyper_rustls::TlsClient::new()))
}\
</%def>
<%def name="_method_call_impl(c, resource, method)" buffered="True">\
<%
mc = new_method_context(resource, method, c)

View File

@@ -14,13 +14,11 @@
</%block>
#![allow(unused_variables, unused_imports, dead_code, unused_mut)]
#[macro_use]
extern crate tokio;
#[macro_use]
extern crate clap;
extern crate yup_oauth2 as oauth2;
extern crate yup_hyper_mock as mock;
extern crate hyper_rustls;
extern crate serde;
extern crate serde_json;

View File

@@ -18,7 +18,6 @@ KEY_VALUE_ARG = 'kv'
SCOPE_FLAG = 'scope'
CONFIG_DIR_FLAG = 'config-dir'
DEBUG_FLAG = 'debug'
DEBUG_AUTH_FLAG = 'debug-auth'
DEFAULT_MIME = 'application/octet-stream'
MODE_ARG = 'mode'