1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright Proa Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
//! `proa font`: vendor and inspect self-hosted, metric-matched fonts
//! (proa_fonts). Fonts are declared in code with `google_font!` /
//! `local_font!`; this command runs the build collector outside a build.
use std::path::PathBuf;
use anyhow::Result;
use clap::{Args, Subcommand};
use crate::font;
use crate::util::resolve_config_root;
#[derive(Debug, Args)]
pub(crate) struct FontArgs {
#[command(subcommand)]
command: FontCommand,
}
#[derive(Debug, Subcommand)]
enum FontCommand {
/// Vendor and lock every font declared in the project's source, or with
/// --offline verify the lock and vendored files instead (the CI gate).
Sync(FontSyncArgs),
/// List fonts recorded in proa-fonts.lock.
List(FontListArgs),
}
#[derive(Debug, Args)]
struct FontSyncArgs {
/// Project root. Defaults to the nearest root.
#[arg(long)]
root: Option<PathBuf>,
/// Verify only: exit non-zero instead of fetching when a declaration is
/// not satisfied by proa-fonts.lock and the vendored files.
#[arg(long)]
offline: bool,
/// Vendored-files directory. Defaults to public/fonts; must match the
/// build script's CollectOptions when that is customized.
#[arg(long, value_name = "DIR")]
fonts_dir: Option<PathBuf>,
/// URL prefix referenced by the generated CSS. Defaults to the asset
/// catalog's fonts directory, /_proa/immutable/fonts.
#[arg(long, value_name = "PREFIX")]
url_prefix: Option<String>,
}
#[derive(Debug, Args)]
struct FontListArgs {
/// Project root. Defaults to the nearest root.
#[arg(long)]
root: Option<PathBuf>,
/// Emit stable JSON.
#[arg(long)]
json: bool,
}
pub(crate) fn run(args: FontArgs) -> Result<()> {
match args.command {
FontCommand::Sync(a) => font::sync(font::SyncOptions {
root: resolve_config_root(a.root)?,
offline: a.offline,
fonts_dir: a.fonts_dir,
url_prefix: a.url_prefix,
}),
FontCommand::List(a) => font::list(resolve_config_root(a.root)?, a.json),
}
}