diff --git a/src/cmd/src/lib.rs b/src/cmd/src/lib.rs index be5f420eb385..848dd5a0496b 100644 --- a/src/cmd/src/lib.rs +++ b/src/cmd/src/lib.rs @@ -65,6 +65,21 @@ pub trait App: Send { } } +/// AppBuilder is a trait builds the App from the options and starts the App. +#[async_trait] +pub trait AppBuilder: Default { + /// Build the options. The final options will be merged from multiple sources(e.g. config file, cli arguments) and stored in the builder. + fn build_options(self) -> Result; + + /// Build the App. After the options are built, the App can be built from the options. + async fn build_app(self) -> Result>; + + /// Build the options and app, then start the app. + async fn start(self) -> Result<()> { + self.build_options()?.build_app().await?.run().await + } +} + /// Log the versions of the application, and the arguments passed to the cli. /// `version_string` should be the same as the output of cli "--version"; /// and the `app_version` is the short version of the codes, often consist of git branch and commit.