online Minecraft written book viewer
at main 110 lines 3.4 kB view raw
1use std::path::PathBuf; 2 3use clap::{ArgAction, Args, Parser, Subcommand}; 4 5use crate::web::TextureKind; 6 7#[derive(Parser, Debug)] 8#[command(version, about, long_about = None)] 9pub struct Cli { 10 #[command(subcommand)] 11 pub command: Command, 12} 13 14#[derive(Subcommand, Debug)] 15pub enum Command { 16 /// Build the library and optionally run the webserver. 17 Serve(ServeArgs), 18 /// Slurp a world directory. 19 SlurpWorld(SlurpWorldArgs), 20 /// Slurp an Infinity Item Editor realm. 21 SlurpRealm(SlurpRealmArgs), 22} 23 24#[derive(Debug, Clone, Copy, clap::ValueEnum)] 25#[clap(rename_all = "snake_case")] 26pub enum MinecraftVersion { 27 V1_12, 28} 29 30#[derive(Args, Debug)] 31pub struct SlurpRealmArgs { 32 #[arg(short = 'v', long = "version", default_value = "v1_12")] 33 pub version: MinecraftVersion, 34 35 /// The path to the `realm.nbt` file created by Infinity Item Editor. 36 #[arg(short = 'r', long = "realm", default_value = "realm.nbt")] 37 pub realm_path: PathBuf, 38 39 /// Path to the book container to create or update. 40 #[arg( 41 short = 'c', 42 long = "container", 43 default_value = "container.json.gz" 44 )] 45 pub container_path: PathBuf, 46} 47 48#[derive(Args, Debug)] 49pub struct SlurpWorldArgs { 50 #[arg(short = 'v', long = "version", default_value = "v1_12")] 51 pub version: MinecraftVersion, 52 53 /// Path to the world directory. 54 #[arg(short = 'w', long = "world")] 55 pub world_path: PathBuf, 56 57 /// Number of worker threads used for parallel file slurping. 58 /// Defaults to the number of logical CPUs. 59 #[arg(short = 'j', long = "workers")] 60 pub workers: Option<usize>, 61 62 /// Path to the book container to create or update. 63 #[arg( 64 short = 'c', 65 long = "container", 66 default_value = "container.json.gz" 67 )] 68 pub container_path: PathBuf, 69} 70 71#[derive(Args, Debug)] 72pub struct ServeArgs { 73 /// Whether to warn about empty/whitespace books being skipped during indexing. 74 #[arg(short = 'e', long, default_value_t = true, action = ArgAction::Set)] 75 pub warn_empty: bool, 76 /// Whether to skip indexing books whose plain-text content is empty/whitespace. 77 #[arg(short = 'f', long, default_value_t = true, action = ArgAction::Set)] 78 pub filter_empty_books: bool, 79 80 /// The score threshold for fuzzy finding book content. 81 #[arg(short = 'C', long, default_value_t = 0.78)] 82 pub content_threshold: f64, 83 /// The score threshold for fuzzy finding book titles. 84 #[arg(short = 'T', long, default_value_t = 0.80)] 85 pub title_threshold: f64, 86 /// The score threshold for fuzzy finding book authors. 87 #[arg(short = 'A', long, default_value_t = 0.82)] 88 pub author_threshold: f64, 89 90 /// Path to the book container to load. 91 #[arg( 92 short = 'c', 93 long = "container", 94 default_value = "container.json.gz" 95 )] 96 pub container_path: PathBuf, 97 98 #[arg(short = 's', long = "dont-start-webserver", action = ArgAction::SetFalse)] 99 pub start_webserver: bool, 100 /// Address to bind the webserver to. 101 #[arg( 102 short = 'a', 103 long = "host-address", 104 default_value = "127.0.0.1:3000" 105 )] 106 pub webserver_host_address: String, 107 /// Minecraft block/item texture variants to serve by default. 108 #[arg(short, long, value_enum, default_value = "modern")] 109 pub ui_textures: TextureKind, 110}