Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

ledger-tool: Switch subcommand dispatch from if-else to match #34644

Merged
merged 2 commits into from
Jan 4, 2024

Conversation

steviez
Copy link
Contributor

@steviez steviez commented Jan 3, 2024

Problem

A future change will add more cases to this if-else if-...-else chain. Using a match statement will be easier to follow then a very long if-else if-... chain.

This change was broken out in order to have a higher signal to noise ratio in the subsequent change.

Summary of Changes

Switch if-else over to match, and then run cargo fmt which will adjust white space in a lot of places. The downstream PR that would build on top of this is #34597. Namely, this section here would look like this with the match statement:

    match matches.subcommand() {
        ("bigtable", Some(arg_matches)) => bigtable_process_command(&ledger_path, arg_matches),
        ("blockstore", Some(arg_matches)) => blockstore_process_command(&ledger_path, arg_matches),
        ("program", Some(arg_matches)) => program(&ledger_path, arg_matches),
        // This match case provides legacy support for commands that were previously top level
        // subcommands of the binary, but have been moved under the blockstore subcommand.
        ("analyze-storage", Some(_))
        | ("bounds", Some(_))
        | ("copy", Some(_))
        | ("dead-slots", Some(_))
        | ("duplicate-slots", Some(_))
        | ("json", Some(_))
        | ("latest-optimistic-slots", Some(_))
        | ("list-roots", Some(_))
        | ("parse_full_frozen", Some(_))
        | ("print", Some(_))
        | ("print-file-metadata", Some(_))
        | ("purge", Some(_))
        | ("remove-dead-slot", Some(_))
        | ("repair-roots", Some(_))
        | ("set-dead-slot", Some(_))
        | ("shred-meta", Some(_))
        | ("slot", Some(_)) => blockstore_process_command(&ledger_path, &matches),
        _ => {

This PR is probably only necessary if we desire to push to #34597; so while this PR should go in first, we may want to confirm that we like the changes introduced by #34597 first.

The first commit is the actual change, the rest is a result of new indentation and line wrapping form cargo fmt

Steven Czabaniuk added 2 commits January 3, 2024 16:47
A future change will add more cases to this if-else if-...-else chain.
Using a match statement will be easier to follow then a very long
if-else if-... chain.

This change was broken out in order to have a higher signal to noise
ratio in the subsequent change.
Copy link

codecov bot commented Jan 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0b49d82) 81.8% compared to head (d2a4d94) 81.8%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #34644   +/-   ##
=======================================
  Coverage    81.8%    81.8%           
=======================================
  Files         824      824           
  Lines      222393   222393           
=======================================
+ Hits       181954   181995   +41     
+ Misses      40439    40398   -41     

Copy link
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, much better. Way to pad those addition/deletion stats, too ;)

@steviez
Copy link
Contributor Author

steviez commented Jan 4, 2024

Way to pad those addition/deletion stats, too ;)

Haha, it was a match statement before #21575 😉 🙈

@steviez steviez merged commit 744c2cb into solana-labs:master Jan 4, 2024
35 checks passed
@steviez steviez deleted the lt_subcommand_match branch January 4, 2024 03:53
@CriesofCarrots
Copy link
Contributor

Haha, it was a match statement before #21575 😉 🙈

Lol! Mea culpa.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants