-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up roadster CLI and custom app CLI
- Loading branch information
1 parent
b087812
commit 6b2fa49
Showing
11 changed files
with
279 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use async_trait::async_trait; | ||
use clap::{Parser, Subcommand}; | ||
|
||
use roadster::app_context::AppContext; | ||
use roadster::cli::RunCommand; | ||
|
||
use crate::app_state::AppState; | ||
|
||
/// Custom version of [RunCommand] that removes the `C` and `S` generics because we know what they | ||
/// are so we don't need to provide them every time we want to implement a command. | ||
#[async_trait] | ||
pub trait RunAppCommand { | ||
async fn run(&self, cli: &AppCli, state: &AppState) -> anyhow::Result<bool>; | ||
} | ||
|
||
/// Minimal Example: Commands specific to managing the `minimal` app are provided in the CLI | ||
/// as well. Subcommands not listed under the `roadster` subcommand are specific to `minimal`. | ||
#[derive(Debug, Parser)] | ||
#[command(version, about)] | ||
pub struct AppCli { | ||
#[command(subcommand)] | ||
pub command: Option<AppCommand>, | ||
} | ||
|
||
#[async_trait] | ||
impl RunCommand<AppCli, AppState> for AppCli { | ||
#[allow(clippy::disallowed_types)] | ||
async fn run( | ||
&self, | ||
cli: &AppCli, | ||
_context: &AppContext, | ||
state: &AppState, | ||
) -> anyhow::Result<bool> { | ||
if let Some(command) = self.command.as_ref() { | ||
command.run(cli, state).await | ||
} else { | ||
Ok(false) | ||
} | ||
} | ||
} | ||
|
||
/// App specific subcommands | ||
/// | ||
/// Note: This doc comment doesn't appear in the CLI `--help` message. | ||
#[derive(Debug, Subcommand)] | ||
pub enum AppCommand {} | ||
|
||
#[async_trait] | ||
impl RunAppCommand for AppCommand { | ||
async fn run(&self, _cli: &AppCli, _state: &AppState) -> anyhow::Result<bool> { | ||
Ok(false) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod app; | ||
pub mod app_state; | ||
pub mod cli; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
use migration::Migrator; | ||
use minimal::app::App; | ||
use roadster::app; | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
app::start::<App, Migrator>().await?; | ||
app::start::<App>().await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.