crates_registry/cli.rs
1use std::{net::SocketAddr, path::PathBuf, str::FromStr};
2
3use clap::{Args, Parser, Subcommand};
4
5#[derive(Parser)]
6#[command(author, version, about, long_about = None)]
7#[command(propagate_version = true)]
8pub struct Cli {
9 #[command(subcommand)]
10 pub command: Commands,
11 /// Increase verbosity (can be supplied multiple times).
12 #[arg(short, long, global = true, default_value_t = 1)]
13 pub verbosity: usize,
14}
15
16#[derive(Subcommand)]
17pub enum Commands {
18 /// Pack Rust installations to serve later.
19 Pack(PackArgs),
20 /// Print all available platforms installations to the stdout.
21 PlatformsList,
22 /// Unpack Rust installation before serving into root registry.
23 Unpack(UnpackArgs),
24 /// Serve offline crates registry.
25 Serve(ServeArgs),
26}
27
28#[derive(Args)]
29pub struct UnpackArgs {
30 /// Path to the src compressed file (we support tar file).
31 #[arg(short, long)]
32 pub packed_file: PathBuf,
33 /// Extract the compressed file here (Be carefull this will override some files).
34 #[arg(short, long)]
35 pub root_registry: PathBuf,
36}
37
38#[derive(Args)]
39pub struct PackArgs {
40 /// Path to the dst compressed file.
41 #[arg(short, long)]
42 pub(crate) pack_file: PathBuf,
43 /// The rust versions for collecting all installation files seperated by comma.
44 /// Valid versions could be "1.67.1", "1.54", and "nightly-2014-12-18".
45 /// In emptry case, Crates-Registry will pack the latest versions of the stable release and the nightly release.
46 #[arg(short, long, value_delimiter=',')]
47 pub(crate) rust_versions: Vec<String>,
48 /// The platforms for collecting seperated by comma.
49 /// You can run `crates-registry platfroms-list` to show all available platfroms.
50 /// Valid platforms could be x86_64-unknown-linux-gnu or x86_64-pc-windows-msvc.
51 #[arg(long, value_delimiter=',')]
52 pub(crate) platforms: Vec<String>,
53 /// Number of downloads that can be ran in parallel.
54 #[arg(short, long, default_value_t = 16)]
55 pub(crate) threads: usize,
56 /// Where to download rustup files from.
57 #[arg(short, long, default_value = "https://static.rust-lang.org")]
58 pub(crate) source: String,
59 /// Number of download retries before giving up.
60 #[arg(long, default_value_t = 5)]
61 pub(crate) retries: usize,
62}
63
64#[derive(Args)]
65pub struct ServeArgs {
66 /// The root directory of the registry. if the path does not exists Crates-Registry will create it's
67 #[arg(long)]
68 pub root_registry: PathBuf,
69 /// The address to serve on. By default we serve on 0.0.0.0:5000
70 #[arg(short, long, value_parser = SocketAddr::from_str, default_value_t = SocketAddr::from(([0, 0, 0, 0], 5000)))]
71 pub binding_addr: SocketAddr,
72 /// The address of the server. By default the address is the local address: 127.0.0.1:5000
73 #[arg(short, long, value_parser = SocketAddr::from_str, default_value_t = SocketAddr::from(([127, 0, 0, 1], 5000)))]
74 pub server_addr: SocketAddr,
75}