Skip to content

Commit

Permalink
refactor: introduce AppBuilder trait
Browse files Browse the repository at this point in the history
  • Loading branch information
zyy17 committed May 15, 2024
1 parent c944d93 commit 3b9a4ef
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/cmd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self>;

/// Build the App. After the options are built, the App can be built from the options.
async fn build_app(self) -> Result<Box<dyn App>>;

/// 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.
Expand Down

0 comments on commit 3b9a4ef

Please sign in to comment.