refactor: introduce AppBuilder
trait
#3941
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I hereby agree to the terms of the GreptimeDB CLA.
Refer to a related PR or issue link (optional)
What's changed and what's your intention?
NOTE: The PR is now in draft mode for discussion. Since the whole PR may be bigger(>1000 LOC), I will separate it into multiple small PRs and share the important abstraction first.
This PR introduces the new trait in the
cmd/
crate calledAppBuilder
. It's a simple abstraction based on the original code that makes our cli structure cleaner.Based on the original design, we can have the following concept:
App
: For most scenarios, it's a running service, for example, frontend, metasrv, etc. Also, it can be a cli tool. Each subcommand can be treated asApp
;AppBuilder
: The builder of theApp
;Options
: For building theApp
, we needOptions
. For most scenarios,Options
can implementConfigurable
trait;We can use the
AppBuilder
to build and run theApp
:The original implementation has many
build()
andload_options()
, which seems too complicated. If we useAppBuilder
, the code can be:AppBuilder
, then build and run theApp
;frontend.rs
/datanode.rs
/metasrv.rs
/cli.rs
) only needs to implementAppBuilder
;The following is the snippet of the code:
For each
App
, we need to create theAppBuilder
struct and implement the trait(most methods are from the original implementation). Takecmd/datanode.rs
for example:There are some references for implementation:
src/bin/greptime.rs
src/datanode.rs
Checklist