Documentation
use clap::{Parser, Subcommand};
use poems::*;

#[derive(Parser)]
#[clap(author, version, about = "poem by example")]
struct Executable {
    #[clap(subcommand)]
    command: Command,
}

#[derive(Subcommand)]
enum Command {
    #[clap(name = "hello")]
    #[clap(author, version, about = "Hello world")]
    Hello(hello::Options),
    #[clap(name = "hello-ws")]
    #[clap(author, version, about = "Hello world w/ websocket")]
    HelloWs(hello_ws::Options),
    #[clap(name = "hello-openapi")]
    #[clap(author, version, about = "Hello world w/ openapi")]
    HelloOpenapi(hello_openapi::Options),
    #[clap(name = "hello-404")]
    #[clap(author, version, about = "Hello world w/ 404 handler")]
    Hello404(hello_404::Options),
    #[clap(name = "hello-debug")]
    #[clap(author, version, about = "Hello world w/ debug")]
    HelloDebug(hello_debug::Options),
    #[clap(name = "hello-tracing")]
    #[clap(author, version, about = "Hello world w/ tracing")]
    HelloTracing(hello_tracing::Options),
    #[clap(name = "hello-logger")]
    #[clap(author, version, about = "Hello world w/ logger")]
    HelloLogger(hello_logger::Options),
    #[clap(name = "hello-world")]
    #[clap(author, version, about = "Hello world w/ manual endpoint impl")]
    HelloWorld(hello_world::Options),
    #[clap(name = "hello-unix")]
    #[clap(author, version, about = "Hello world, unix domain socket")]
    HelloUnix(hello_unix::Options),
    #[clap(name = "hello-id")]
    #[clap(author, version, about = "Hello world, /hello/:id, /hello/:id/:name")]
    HelloId(hello_id::Options),
    #[clap(name = "nothing")]
    #[clap(author, version, about = "Nothing")]
    Nothing(nothing::Options),
    #[clap(name = "echo")]
    #[clap(author, version, about = "Echo request")]
    Echo(echo::Options),
    #[clap(name = "yaml")]
    #[clap(author, version, about = "Echo request (yaml)")]
    Yaml(yaml::Options),
    #[clap(name = "ser")]
    #[clap(author, version, about = "Serve static files")]
    Ser(ser::Options),
}

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
    Ok(match Executable::parse().command {
        Command::Hello(mut options) => {
            options.run().await?;
        }
        Command::HelloWs(mut options) => {
            options.run().await?;
        }
        Command::HelloOpenapi(mut options) => {
            options.run().await?;
        }
        Command::Hello404(mut options) => {
            options.run().await?;
        }
        Command::HelloDebug(mut options) => {
            options.run().await?;
        }
        Command::HelloTracing(mut options) => {
            options.run().await?;
        }
        Command::HelloLogger(mut options) => {
            options.run().await?;
        }
        Command::HelloWorld(mut options) => {
            options.run().await?;
        }
        Command::HelloId(mut options) => {
            options.run().await?;
        }
        Command::HelloUnix(mut options) => {
            options.run().await?;
        }
        Command::Nothing(mut options) => {
            options.run().await?;
        }
        Command::Echo(mut options) => {
            options.run().await?;
        }
        Command::Yaml(mut options) => {
            options.run().await?;
        }
        Command::Ser(mut options) => {
            options.run().await?;
        }
    })
}