Skip to main content

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_APP_ID, ZR_CACHE_DIR, ZR_CRATE_NAME, ZR_DESCRIPTION, 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_VERBOSE,
27        ZR_VERSION, 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    /// Use verbose output (-vv very verbose)
49    #[arg(
50        long,
51        short = 'v',
52        action = clap::ArgAction::Count,
53        global = true,
54    )]
55    verbose: u8,
56}
57
58#[derive(Subcommand, Debug)]
59enum Command {
60    /// Format code and macros
61    ///
62    /// Runs cargo fmt and formats Zng macros
63    Fmt(fmt::FmtArgs),
64    /// New project from a Zng template repository.
65    New(new::NewArgs),
66    /// Localization text scraper
67    ///
68    /// See the docs for `l10n!` for more details about the expected format.
69    L10n(l10n::L10nArgs),
70
71    /// Build resources
72    ///
73    /// Builds resources SOURCE to TARGET, delegates `'{tool}` files to `cargo-zng-res-{tool}`
74    /// executables and crates.
75    Res(res::ResArgs),
76
77    /// Run an app with trace recording enabled.
78    ///
79    /// The app must be built with `"trace_recorder"` feature enabled.
80    Trace(trace::TraceArgs),
81}
82
83fn main() {
84    res::built_in::run();
85
86    let CargoCli::Zng(cli) = CargoCli::parse();
87
88    util::set_verbose(cli.verbose);
89
90    match cli.command {
91        Command::Fmt(args) => fmt::run(args),
92        Command::New(args) => new::run(args),
93        Command::L10n(args) => l10n::run(args),
94        Command::Res(args) => res::run(args),
95        Command::Trace(args) => trace::run(args),
96    }
97
98    crate::util::exit();
99}