Skip to main content

topcoat_cli/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3mod asset;
4mod common;
5mod dev;
6mod fmt;
7mod l10n;
8mod new;
9mod ui;
10
11use clap::{Parser, Subcommand};
12
13#[derive(Parser)]
14#[command(name = "topcoat", version)]
15pub struct TopcoatCli {
16    #[command(subcommand)]
17    command: Command,
18}
19
20impl TopcoatCli {
21    pub async fn run(self) {
22        match self.command {
23            Command::New(cmd) => cmd.run(),
24            Command::Ui(cmd) => cmd.run(),
25            Command::Fmt(cmd) => cmd.run().await,
26            Command::Dev(cmd) => cmd.run().await,
27            Command::Asset(cmd) => cmd.run().await,
28            Command::L10n(cmd) => cmd.run().await,
29        }
30    }
31}
32
33#[derive(Subcommand)]
34enum Command {
35    /// Create a new Topcoat application
36    New(new::NewCommand),
37    /// Start a development server
38    Dev(dev::DevCommand),
39    /// Format Topcoat macro bodies
40    Fmt(fmt::FmtCommand),
41    /// Inspect assets embedded in the binary
42    Asset(asset::AssetCommand),
43    /// Check the app's translations
44    L10n(l10n::L10nCommand),
45    /// Manage premade UI components in your project
46    Ui(ui::UiCommand),
47}
48
49pub async fn run() {
50    run_from(std::env::args_os()).await;
51}
52
53pub async fn run_from(args: impl IntoIterator<Item = std::ffi::OsString>) {
54    common::version::warn_on_mismatch();
55    TopcoatCli::parse_from(args).run().await;
56}