Skip to content

Commit

Permalink
fix(zebrad) print usage info for --help flag (#5634)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Nov 18, 2022
1 parent bd54a2f commit a2f2a14
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion zebrad/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions zebrad/src/application/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 6 additions & 3 deletions zebrad/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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"
Expand Down

0 comments on commit a2f2a14

Please sign in to comment.