cargo_zng/
main.rs

1#![doc(html_favicon_url = "https://zng-ui.github.io/res/zng-logo-icon.png")]
2#![doc(html_logo_url = "https://zng-ui.github.io/res/zng-logo.png")]
3//!
4//! Zng project management.
5//!
6//! # Crate
7//!
8#![doc = include_str!(concat!("../", std::env!("CARGO_PKG_README")))]
9#![warn(unused_extern_crates)]
10#![warn(missing_docs)]
11
12#[macro_use]
13mod util;
14mod fmt;
15mod l10n;
16mod new;
17mod res;
18mod trace;
19
20/// Utilities for implementing `cargo-zng-res-{tool}` executables.
21///
22/// Note don't depend on `cargo-zng`, just copy the source code of the utilities you need.
23pub mod res_tool_util {
24    pub use crate::res::built_in::{
25        ZR_APP, ZR_CACHE_DIR, ZR_CRATE_NAME, ZR_DESCRIPTION, ZR_FINAL, ZR_HELP, ZR_HOMEPAGE, ZR_LICENSE, ZR_ORG, ZR_PKG_AUTHORS,
26        ZR_PKG_NAME, ZR_QUALIFIER, ZR_REQUEST, ZR_REQUEST_DD, ZR_SOURCE_DIR, ZR_TARGET, ZR_TARGET_DD, ZR_TARGET_DIR, ZR_VERSION,
27        ZR_WORKSPACE_DIR, display_path, path,
28    };
29}
30
31use clap::*;
32
33#[derive(Parser)] // requires `derive` feature
34#[command(name = "cargo")]
35#[command(bin_name = "cargo")]
36enum CargoCli {
37    Zng(Zng),
38}
39
40#[derive(Args, Debug)]
41#[command(author, version, about, long_about = None)]
42#[command(propagate_version = true)]
43struct Zng {
44    /// Command.
45    #[command(subcommand)]
46    pub command: Command,
47}
48
49#[derive(Subcommand, Debug)]
50enum Command {
51    /// Format code and macros
52    ///
53    /// Runs cargo fmt and formats Zng macros
54    Fmt(fmt::FmtArgs),
55    /// New project from a Zng template repository.
56    New(new::NewArgs),
57    /// Localization text scraper
58    ///
59    /// See the docs for `l10n!` for more details about the expected format.
60    L10n(l10n::L10nArgs),
61
62    /// Build resources
63    ///
64    /// Builds resources SOURCE to TARGET, delegates `.zr-{tool}` files to `cargo-zng-res-{tool}`
65    /// executables and crates.
66    Res(res::ResArgs),
67
68    /// Run an app with trace recording enabled.
69    ///
70    /// The app must be built with `"trace_recorder"` feature enabled.
71    Trace(trace::TraceArgs),
72}
73
74fn main() {
75    res::built_in::run();
76
77    let CargoCli::Zng(cli) = CargoCli::parse();
78
79    match cli.command {
80        Command::Fmt(args) => fmt::run(args),
81        Command::New(args) => new::run(args),
82        Command::L10n(args) => l10n::run(args),
83        Command::Res(args) => res::run(args),
84        Command::Trace(args) => trace::run(args),
85    }
86
87    crate::util::exit();
88}