cargo_zng/
main.rs

1#![doc(html_favicon_url = "https://raw.githubusercontent.com/zng-ui/zng/main/examples/image/res/zng-logo-icon.png")]
2#![doc(html_logo_url = "https://raw.githubusercontent.com/zng-ui/zng/main/examples/image/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;
18
19/// Utilities for implementing `cargo-zng-res-{tool}` executables.
20///
21/// Note don't depend on `cargo-zng`, just copy the source code of the utilities you need.
22pub mod res_tool_util {
23    pub use crate::res::built_in::{
24        ZR_APP, ZR_CACHE_DIR, ZR_CRATE_NAME, ZR_DESCRIPTION, ZR_FINAL, ZR_HELP, ZR_HOMEPAGE, ZR_LICENSE, ZR_ORG, ZR_PKG_AUTHORS,
25        ZR_PKG_NAME, ZR_QUALIFIER, ZR_REQUEST, ZR_REQUEST_DD, ZR_SOURCE_DIR, ZR_TARGET, ZR_TARGET_DD, ZR_TARGET_DIR, ZR_VERSION,
26        ZR_WORKSPACE_DIR, display_path, path,
27    };
28}
29
30use clap::*;
31
32#[derive(Parser)] // requires `derive` feature
33#[command(name = "cargo")]
34#[command(bin_name = "cargo")]
35enum CargoCli {
36    Zng(Zng),
37}
38
39#[derive(Args, Debug)]
40#[command(author, version, about, long_about = None)]
41#[command(propagate_version = true)]
42struct Zng {
43    /// Command.
44    #[command(subcommand)]
45    pub command: Command,
46}
47
48#[derive(Subcommand, Debug)]
49enum Command {
50    /// Format code and macros
51    ///
52    /// Runs cargo fmt and formats Zng macros
53    Fmt(fmt::FmtArgs),
54    /// New project from a Zng template repository.
55    New(new::NewArgs),
56    /// Localization text scraper
57    ///
58    /// See the docs for `l10n!` for more details about the expected format.
59    L10n(l10n::L10nArgs),
60
61    /// Build resources
62    ///
63    /// Builds resources SOURCE to TARGET, delegates `.zr-{tool}` files to `cargo-zng-res-{tool}`
64    /// executables and crates.
65    Res(res::ResArgs),
66}
67
68fn main() {
69    res::built_in::run();
70
71    let CargoCli::Zng(cli) = CargoCli::parse();
72
73    match cli.command {
74        Command::Fmt(args) => fmt::run(args),
75        Command::New(args) => new::run(args),
76        Command::L10n(args) => l10n::run(args),
77        Command::Res(args) => res::run(args),
78    }
79
80    crate::util::exit();
81}