tangled
alpha
login
or
join now
kokirigla.de
/
nara
0
fork
atom
online Minecraft written book viewer
0
fork
atom
overview
issues
pulls
pipelines
feat: split cli
kokirigla.de
3 weeks ago
0c4853e8
982ec075
verified
This commit was signed with the committer's
known signature
.
kokirigla.de
SSH Key Fingerprint:
SHA256:BlSEtD3ZoKT3iKveofI8gba+lZ9CEolKRM1Pzy3pAwg=
+29
-12
3 changed files
expand all
collapse all
unified
split
src
cli.rs
main.rs
web.rs
+14
-2
src/cli.rs
···
1
1
use std::path::PathBuf;
2
2
3
3
-
use clap::{ArgAction, Parser};
3
3
+
use clap::{ArgAction, Args, Parser, Subcommand};
4
4
5
5
use crate::web::TextureKind;
6
6
7
7
#[derive(Parser, Debug)]
8
8
#[command(version, about, long_about = None)]
9
9
-
pub struct Args {
9
9
+
pub struct Cli {
10
10
+
#[command(subcommand)]
11
11
+
pub command: Command,
12
12
+
}
13
13
+
14
14
+
#[derive(Subcommand, Debug)]
15
15
+
pub enum Command {
16
16
+
/// Build the library and optionally run the webserver.
17
17
+
Serve(ServeArgs),
18
18
+
}
19
19
+
20
20
+
#[derive(Args, Debug)]
21
21
+
pub struct ServeArgs {
10
22
/// The path to the `realm.nbt` file created by Infinity Item Editor.
11
23
#[arg(short = 'r', long = "realm", default_value = "realm.nbt")]
12
24
pub realm_path: PathBuf,
+13
-8
src/main.rs
···
4
4
use clap::Parser as _;
5
5
6
6
use crate::{
7
7
-
cli::Args,
7
7
+
cli::{Cli, Command, ServeArgs},
8
8
library::{Library, Realm},
9
9
web::start_webserver,
10
10
};
···
18
18
#[tokio::main]
19
19
async fn main() -> anyhow::Result<()> {
20
20
tracing_subscriber::fmt::init();
21
21
-
let cli_args = Args::parse();
22
22
-
let library = build_library(&cli_args).context("Building library")?;
21
21
+
let cli = Cli::parse();
22
22
+
23
23
+
match cli.command {
24
24
+
Command::Serve(args) => {
25
25
+
let library = build_library(&args).context("Building library")?;
23
26
24
24
-
if cli_args.start_webserver {
25
25
-
start_webserver(&cli_args, library)
26
26
-
.await
27
27
-
.context("Running webserver")?;
27
27
+
if args.start_webserver {
28
28
+
start_webserver(&args, library)
29
29
+
.await
30
30
+
.context("Running webserver")?;
31
31
+
}
32
32
+
}
28
33
}
29
34
30
35
Ok(())
31
36
}
32
37
33
33
-
fn build_library(args: &Args) -> anyhow::Result<Library> {
38
38
+
fn build_library(args: &ServeArgs) -> anyhow::Result<Library> {
34
39
let realm_path = &args.realm_path;
35
40
36
41
if !fs::exists(realm_path)
+2
-2
src/web.rs
···
8
8
use tokio::net::TcpListener;
9
9
use tower_http::compression::CompressionLayer;
10
10
11
11
-
use crate::{cli::Args, library::Library};
11
11
+
use crate::{cli::ServeArgs, library::Library};
12
12
13
13
pub mod api;
14
14
pub mod assets;
···
32
32
}
33
33
34
34
pub async fn start_webserver(
35
35
-
args: &Args,
35
35
+
args: &ServeArgs,
36
36
library: Library,
37
37
) -> anyhow::Result<()> {
38
38
let library = Arc::new(Mutex::new(library));