fix(zebrad) print usage info for --help flag (#5634)

* print usage info for --help flag

* update known issues and help command's help text

* Update README.md

Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>

* updates README

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
This commit is contained in:
Arya 2022-11-18 09:24:10 -05:00 committed by GitHub
parent bd54a2f40e
commit a2f2a1402e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 4 deletions

View File

@ -242,6 +242,8 @@ There are a few bugs in Zebra that we're still working on fixing:
- Experimental Tor support is disabled until [`arti-client` upgrades to `x25519-dalek` 2.0.0 or later](https://github.com/ZcashFoundation/zebra/issues/5492)
- This happens due to a Rust dependency conflict, which can only be resolved by changing the dependencies of `x25519-dalek`
- Output of `help`, `--help` flag, and usage of invalid commands or options are inconsistent. Reports of these issues can be found [here](https://github.com/ZcashFoundation/zebra/issues/5502) and are planned to be fixed in the context of [upgrading Abscissa](https://github.com/ZcashFoundation/zebra/issues/5502).
## Future Work
Performance and Reliability:

View File

@ -376,7 +376,7 @@ impl Application for ZebradApp {
let default_filter = command
.command
.as_ref()
.map(|zcmd| zcmd.default_tracing_filter(command.verbose))
.map(|zcmd| zcmd.default_tracing_filter(command.verbose, command.help))
.unwrap_or("warn");
let is_server = command
.command

View File

@ -42,6 +42,13 @@ pub struct EntryPoint {
impl EntryPoint {
/// Borrow the underlying command type
fn command(&self) -> &ZebradCmd {
if self.help {
let _ = Usage::for_command::<EntryPoint>().print_info();
let _ = Usage::for_command::<EntryPoint>().print_usage();
let _ = Usage::for_command::<ZebradCmd>().print_usage();
std::process::exit(0);
}
self.command
.as_ref()
.expect("Some(ZebradCmd::Start(StartCmd::default()) as default value")

View File

@ -42,7 +42,9 @@ pub enum ZebradCmd {
Generate(GenerateCmd),
/// The `help` subcommand
#[options(help = "get usage information")]
#[options(help = "get usage information, \
use help <subcommand> for subcommand usage information, \
or --help flag to see top-level options")]
Help(Help<Self>),
/// The `start` subcommand
@ -78,7 +80,7 @@ impl ZebradCmd {
/// Returns the default log level for this command, based on the `verbose` command line flag.
///
/// Some commands need to be quiet by default.
pub(crate) fn default_tracing_filter(&self, verbose: bool) -> &'static str {
pub(crate) fn default_tracing_filter(&self, verbose: bool, help: bool) -> &'static str {
let only_show_warnings = match self {
// Commands that generate quiet output by default.
// This output:
@ -90,7 +92,8 @@ impl ZebradCmd {
CopyState(_) | Download(_) | Start(_) => false,
};
if only_show_warnings && !verbose {
// set to warn so that usage info is printed without info-level logs from component registration
if help || (only_show_warnings && !verbose) {
"warn"
} else if only_show_warnings || !verbose {
"info"