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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
use std::net::SocketAddr;
use std::path::PathBuf;
use std::process::ExitCode;
use std::time::Duration;
use clap::{Args, Parser, Subcommand, ValueEnum};
use tracing_subscriber::EnvFilter;
use hazine::setup::{self, Catalog, SslMode, Storage, UrlStyle};
use hazine::{Config, supervisor, token};
/// Run a DuckDB Quack server for DuckLake on localhost.
///
/// Settings come from flags, then HAZINE_* environment variables, then
/// defaults. Quack listens on a loopback address only: connect through an SSH
/// tunnel (ssh -N -L 1294:127.0.0.1:1294 <host>).
#[derive(Parser)]
#[command(version, about)]
struct Cli {
/// Log format.
#[arg(
long,
env = "HAZINE_LOG_FORMAT",
value_enum,
default_value_t,
global = true
)]
log_format: LogFormat,
#[command(subcommand)]
command: Command,
}
#[derive(Clone, Copy, Default, ValueEnum)]
enum LogFormat {
#[default]
Text,
Json,
}
#[derive(Subcommand)]
enum Command {
/// Start DuckDB with the init file and keep it serving Quack.
Serve(ServeArgs),
/// Install and configure hazine, DuckDB and the systemd service (as root,
/// on Linux). Rerun to change settings; existing secrets are kept.
///
/// Give secrets through environment variables rather than flags, which
/// other users can see in the process list; missing ones are asked for.
Setup(Box<SetupArgs>),
/// Open a hazine server in the DuckDB UI on this machine, through an SSH
/// tunnel. Quit DuckDB (.exit or Ctrl-D) to close the tunnel.
///
/// The token is read from the server's /etc/hazine/hazine.env with
/// `sudo -n`, unless HAZINE_TOKEN is set.
Ui(UiArgs),
/// Import the OpenAlex snapshot into the lake, and query it (on the
/// server, as root).
#[command(subcommand)]
Openalex(OpenalexCommand),
/// Import the ROR data dump from Zenodo into the lake, and query it (on
/// the server, as root).
#[command(subcommand)]
Ror(RorCommand),
/// Import the ORCID Public Data File summaries into the lake, and query
/// them (on the server, as root).
#[command(subcommand)]
Orcid(OrcidCommand),
/// Import the COMET enrichments of DataCite records into the lake, and
/// query them (on the server, as root).
#[command(subcommand)]
Comet(CometCommand),
/// Print a new random access token, for QUACK_TOKEN.
Token {
/// Characters in the token.
#[arg(long, default_value_t = 40)]
length: usize,
},
}
#[derive(Args)]
struct ServeArgs {
/// The DuckDB CLI (≥ 2.0, with the quack extension installed): a path,
/// or a name looked up in PATH.
#[arg(long, env = "HAZINE_DUCKDB", default_value = "duckdb")]
duckdb: PathBuf,
/// SQL run at start: settings, extensions, the DuckLake attach and
/// quack_serve, which should listen on getenv('HAZINE_QUACK_ADDR').
#[arg(long, env = "HAZINE_INIT", default_value = "/etc/hazine/init.sql")]
init: PathBuf,
/// The main database: a DuckDB file, or a DuckLake such as
/// ducklake:postgres: (what hazine setup configures); in memory without
/// one. Every Quack session uses it by default.
#[arg(long, env = "HAZINE_DATABASE")]
database: Option<PathBuf>,
/// Where Quack listens; handed to the init file as HAZINE_QUACK_ADDR.
/// Must be a loopback address.
#[arg(long, env = "HAZINE_QUACK_ADDR", default_value = "127.0.0.1:1294")]
quack_addr: SocketAddr,
/// Seconds DuckDB may take to start listening before hazine warns.
#[arg(long, env = "HAZINE_READY_TIMEOUT", default_value_t = 60)]
ready_timeout: u64,
/// Seconds DuckDB has to exit on shutdown before it is killed.
#[arg(long, env = "HAZINE_STOP_TIMEOUT", default_value_t = 30)]
stop_timeout: u64,
/// Exits in a row before Quack was listening after which hazine gives up
/// (and exits non-zero, for the service manager to see).
#[arg(long, env = "HAZINE_MAX_FAILURES", default_value_t = 5)]
max_failures: u32,
}
#[derive(Subcommand)]
enum CometCommand {
/// Import the current COMET enrichments (Hugging Face,
/// cometadata/comet-datacite-enrichment-layer-ingest-format) into the
/// lake, as schema comet_<date>_<commit>, e.g. comet_2026_02_06_6f4066e.
///
/// The version is the dataset's latest commit that changed a data file.
/// Its three JSON Lines files are taken from commonmeta's cache (root's,
/// and the sudo user's ~/.cache/commonmeta/comet) when they have that
/// version's sizes, or downloaded there. Each is converted to Parquet; the
/// files and the Parquet parts are stored in the lake's bucket, under
/// sources/comet/<version>/. A version already imported is skipped.
Import {
/// A directory with the three files [default: commonmeta's cache].
#[arg(long, value_name = "DIR")]
dir: Option<PathBuf>,
/// Import again, though this version is imported.
#[arg(long)]
force: bool,
/// Threads for parsing and for DuckDB [default: half the CPUs].
#[arg(long)]
threads: Option<usize>,
/// DuckDB memory_limit for creating the tables, e.g. 30GB [default: a
/// fifth of RAM].
#[arg(long)]
memory_limit: Option<String>,
/// Only write the Parquet parts to this directory; no lake, no root,
/// any OS.
#[arg(long, value_name = "DIR", conflicts_with_all = ["force", "dry_run"])]
output: Option<PathBuf>,
/// Show the version, the files found and what would be imported;
/// change nothing.
#[arg(long)]
dry_run: bool,
},
/// Point the views in the comet schema (comet.enrichments, comet.release)
/// at an imported version.
Setup {
/// The version, e.g. 2026_02_06_6f4066e [default: the newest
/// imported].
#[arg(long)]
release: Option<String>,
/// Print the SQL; change nothing.
#[arg(long)]
dry_run: bool,
},
}
#[derive(Subcommand)]
enum OrcidCommand {
/// Import an ORCID summaries archive (ORCID_<year>_<batch>_summaries.tar.gz)
/// into the lake, as schema orcid_<year>_<batch>, e.g. orcid_2026_10.
///
/// The archive and its Parquet version (parts of 1M records, with each
/// record's XML) are both stored in the lake's bucket, under
/// sources/orcid/<version>/. Without --file, the latest release on
/// figshare is looked for in commonmeta's cache (root's, and the sudo
/// user's ~/.cache/commonmeta/orcid), and downloaded if missing. Takes
/// hours for a full release (about 50 GB); run it in tmux. A version
/// already imported is skipped.
Import {
/// The summaries archive [default: the latest release, from the
/// cache].
#[arg(long)]
file: Option<PathBuf>,
/// Import again, though this version is imported.
#[arg(long)]
force: bool,
/// Threads for parsing and for DuckDB [default: half the CPUs].
#[arg(long)]
threads: Option<usize>,
/// DuckDB memory_limit for creating the tables, e.g. 30GB [default: a
/// fifth of RAM].
#[arg(long)]
memory_limit: Option<String>,
/// Only write the Parquet parts to this directory; no lake, no root,
/// any OS.
#[arg(long, value_name = "DIR", conflicts_with_all = ["force", "dry_run"])]
output: Option<PathBuf>,
/// Show the archive and what would be imported; change nothing.
#[arg(long)]
dry_run: bool,
},
/// Point the views in the orcid schema (orcid.people, orcid.release) at
/// an imported version.
Setup {
/// The version, e.g. 2026_10 [default: the newest imported].
#[arg(long)]
release: Option<String>,
/// Print the SQL; change nothing.
#[arg(long)]
dry_run: bool,
},
}
#[derive(Subcommand)]
enum RorCommand {
/// Import the latest ROR release (Zenodo, 10.5281/zenodo.6347574) into
/// the lake, as schema ror_<version>, e.g. ror_v2_16.
///
/// The JSON in the release's zip is converted to Parquet; the zip and the
/// Parquet file are both stored in the lake's bucket, under
/// sources/ror/<version>/. A version already imported is skipped.
Import {
/// Import again, though this version is imported.
#[arg(long)]
force: bool,
/// Only write the release's zip and its Parquet file to this
/// directory; no lake, no root, any OS.
#[arg(long, value_name = "DIR", conflicts_with_all = ["force", "dry_run"])]
output: Option<PathBuf>,
/// Show the latest release and what would be imported; change
/// nothing.
#[arg(long)]
dry_run: bool,
},
/// Point the views in the ror schema (ror.organizations, ror.release) at
/// an imported version.
Setup {
/// The version, e.g. v2.16 [default: the newest imported].
#[arg(long)]
release: Option<String>,
/// Print the SQL; change nothing.
#[arg(long)]
dry_run: bool,
},
}
#[derive(Subcommand)]
enum OpenalexCommand {
/// Import the current OpenAlex release (Parquet, s3://openalex) into the
/// lake, as schema openalex_<release date>, one table per entity.
///
/// Takes hours for the full release (about 800 GB); run it in tmux. It
/// resumes: tables already complete are kept. It stops if OpenAlex
/// publishes a new release meanwhile.
Import {
/// Only these entities, comma-separated, e.g. works,authors
/// [default: all].
#[arg(long, value_delimiter = ',')]
entities: Vec<String>,
/// DuckDB threads for the import [default: half the CPUs].
#[arg(long)]
threads: Option<usize>,
/// DuckDB memory_limit for the import, e.g. 30GB [default: a fifth of
/// RAM].
#[arg(long)]
memory_limit: Option<String>,
/// Show the release and the tables it would import; change nothing.
#[arg(long)]
dry_run: bool,
},
/// Point the views in the openalex schema (openalex.works, ...) at an
/// imported release.
Setup {
/// The release, e.g. 2026-10-14 [default: the newest imported].
#[arg(long)]
release: Option<String>,
/// Print the SQL; change nothing.
#[arg(long)]
dry_run: bool,
},
}
#[derive(Args)]
struct UiArgs {
/// The server, as for ssh: host, user@host or an ssh_config alias.
host: String,
/// The server's name in DuckDB [default: the first part of the host name,
/// e.g. hermione].
#[arg(long)]
name: Option<String>,
/// The local end of the tunnel.
#[arg(long, default_value_t = 1294)]
local_port: u16,
/// Where the DuckDB UI listens.
#[arg(long, default_value_t = 4213)]
ui_port: u16,
/// The Quack token [default: read from the server].
#[arg(long, env = "HAZINE_TOKEN", hide_env_values = true)]
token: Option<String>,
/// The local DuckDB CLI (2.0 or later).
#[arg(long, env = "HAZINE_DUCKDB", default_value = "duckdb")]
duckdb: PathBuf,
/// A local DuckDB database file to open alongside; in memory without one.
#[arg(long)]
database: Option<PathBuf>,
/// Start the UI server but don't open the browser; DuckDB prints the URL.
#[arg(long)]
no_open: bool,
/// The ssh client.
#[arg(long, default_value = "ssh", hide = true)]
ssh: PathBuf,
}
impl From<UiArgs> for hazine::ui::Options {
fn from(args: UiArgs) -> Self {
hazine::ui::Options {
name: args
.name
.unwrap_or_else(|| hazine::ui::default_name(&args.host)),
host: args.host,
local_port: args.local_port,
ui_port: args.ui_port,
token: args.token,
duckdb: args.duckdb,
database: args.database,
open: !args.no_open,
ssh: args.ssh,
}
}
}
#[derive(Args)]
struct SetupArgs {
/// Postgres host holding the DuckLake catalog [asked for if not given].
#[arg(long, env = "HAZINE_PG_HOST", help_heading = "Catalog (Postgres)")]
pg_host: Option<String>,
/// [default: from the last setup, else 5432]
#[arg(long, env = "HAZINE_PG_PORT", help_heading = "Catalog (Postgres)")]
pg_port: Option<u16>,
/// [default: from the last setup, else ducklake]
#[arg(long, env = "HAZINE_PG_DATABASE", help_heading = "Catalog (Postgres)")]
pg_database: Option<String>,
/// [default: from the last setup, else hazine]
#[arg(long, env = "HAZINE_PG_USER", help_heading = "Catalog (Postgres)")]
pg_user: Option<String>,
/// Kept from the existing env file if not given.
#[arg(
long,
env = "HAZINE_PG_PASSWORD",
hide_env_values = true,
help_heading = "Catalog (Postgres)"
)]
pg_password: Option<String>,
/// TLS to Postgres (libpq's sslmode) [default: from the last setup, else
/// require].
#[arg(
long,
env = "HAZINE_PG_SSLMODE",
value_enum,
help_heading = "Catalog (Postgres)"
)]
pg_sslmode: Option<SslMode>,
/// Where DuckLake writes Parquet files: s3://bucket/prefix/ [asked for if
/// not given].
#[arg(long, env = "HAZINE_DATA_PATH", help_heading = "Data (S3)")]
data_path: Option<String>,
/// S3 endpoint, host[:port], e.g. fsn1.your-objectstorage.com for
/// Hetzner, or "aws" [asked for if not given].
#[arg(long, env = "HAZINE_S3_ENDPOINT", help_heading = "Data (S3)")]
s3_endpoint: Option<String>,
/// S3 region, e.g. fsn1 for Hetzner in Falkenstein [asked for if not
/// given; default: the Hetzner location, else us-east-1].
#[arg(long, env = "HAZINE_S3_REGION", help_heading = "Data (S3)")]
s3_region: Option<String>,
/// vhost or path [asked for if not given; default: path with an
/// endpoint, vhost for AWS].
#[arg(
long,
env = "HAZINE_S3_URL_STYLE",
value_enum,
help_heading = "Data (S3)"
)]
s3_url_style: Option<UrlStyle>,
/// Use HTTPS to the endpoint.
#[arg(long, env = "HAZINE_S3_USE_SSL", default_value_t = true, action = clap::ArgAction::Set, help_heading = "Data (S3)")]
s3_use_ssl: bool,
/// Kept from the existing env file if not given.
#[arg(
long,
env = "HAZINE_S3_KEY_ID",
hide_env_values = true,
help_heading = "Data (S3)"
)]
s3_key_id: Option<String>,
/// Kept from the existing env file if not given.
#[arg(
long,
env = "HAZINE_S3_SECRET",
hide_env_values = true,
help_heading = "Data (S3)"
)]
s3_secret: Option<String>,
/// The DuckDB CLI release to install (2.0 or later).
#[arg(long, env = "HAZINE_DUCKDB_VERSION", default_value = "2.0.1")]
duckdb_version: String,
/// Where Quack listens. Must be a loopback address.
#[arg(long, env = "HAZINE_QUACK_ADDR", default_value = "127.0.0.1:1294")]
quack_addr: SocketAddr,
/// DuckDB threads [default: the number of CPUs].
#[arg(long)]
threads: Option<usize>,
/// DuckDB memory_limit, e.g. 100GB [default: 80% of RAM].
#[arg(long)]
memory_limit: Option<String>,
/// systemd MemoryMax for the service, e.g. 112G [default: 90% of RAM].
#[arg(long)]
memory_max: Option<String>,
/// Configure, but do not enable or restart the service.
#[arg(long)]
no_start: bool,
/// Print what would be done and the files that would be written (secrets
/// redacted); change nothing.
#[arg(long)]
dry_run: bool,
}
impl SetupArgs {
fn into_options(self) -> Result<setup::Options, hazine::Error> {
// Earlier values are offered as defaults when asking.
let existing = setup::existing_env(self.dry_run)?;
let pg_host = setup::setting(
self.pg_host,
existing.get("PGHOST").map(String::as_str),
"--pg-host",
"Postgres host (DuckLake catalog)",
setup::host,
)?;
let data_path = setup::setting(
self.data_path,
existing.get("HAZINE_DATA_PATH").map(String::as_str),
"--data-path",
"Data path (s3://bucket/prefix/)",
setup::render::data_path,
)?;
// Given, else from the last setup, else the built-in default.
let port = match self.pg_port {
Some(port) => port,
None => existing_or(&existing, "PGPORT", "5432")
.parse()
.map_err(|_| hazine::Error::InvalidSetting {
name: "PGPORT in hazine.env",
reason: "is not a port number; give --pg-port".into(),
})?,
};
let database = self
.pg_database
.unwrap_or_else(|| existing_or(&existing, "PGDATABASE", "ducklake").into());
let user = self
.pg_user
.unwrap_or_else(|| existing_or(&existing, "PGUSER", "hazine").into());
let sslmode = match self.pg_sslmode {
Some(sslmode) => sslmode,
None => SslMode::from_str(existing_or(&existing, "PGSSLMODE", "require"), true)
.map_err(|_| hazine::Error::InvalidSetting {
name: "PGSSLMODE in hazine.env",
reason: "is not an sslmode; give --pg-sslmode".into(),
})?,
};
let endpoint = setup::setting(
self.s3_endpoint,
Some(existing_or(
&existing,
"HAZINE_S3_ENDPOINT",
setup::render::AWS,
)),
"--s3-endpoint",
"S3 endpoint (fsn1.your-objectstorage.com for Hetzner in Falkenstein; aws for AWS)",
setup::render::endpoint,
)?;
let endpoint = (endpoint != setup::render::AWS).then_some(endpoint);
// A Hetzner endpoint names its region; otherwise offer the last one.
let region_default = setup::render::region_of(endpoint.as_deref())
.unwrap_or_else(|| existing_or(&existing, "HAZINE_S3_REGION", "us-east-1").into());
let region = setup::setting(
self.s3_region,
Some(®ion_default),
"--s3-region",
"S3 region",
setup::render::region,
)?;
let style_default = if endpoint.is_some() { "path" } else { "vhost" };
let url_style = setup::setting(
self.s3_url_style.map(|style| style.as_str().to_string()),
Some(existing_or(&existing, "HAZINE_S3_URL_STYLE", style_default)),
"--s3-url-style",
"S3 URL style (vhost or path)",
|value| setup::render::url_style(value).map(|style| style.as_str().to_string()),
)?;
let url_style = setup::render::url_style(&url_style)?;
Ok(setup::Options {
catalog: Catalog {
host: pg_host,
port,
database,
user,
sslmode,
},
storage: Storage {
data_path,
endpoint,
region,
url_style,
use_ssl: self.s3_use_ssl,
},
pg_password: self.pg_password,
s3_key_id: self.s3_key_id,
s3_secret: self.s3_secret,
duckdb_version: self.duckdb_version,
quack_addr: self.quack_addr,
threads: self.threads,
memory_limit: self.memory_limit,
memory_max: self.memory_max,
start: !self.no_start,
dry_run: self.dry_run,
})
}
}
/// The value of `name` in the existing env file, or `fallback`.
fn existing_or<'a>(
existing: &'a std::collections::HashMap<String, String>,
name: &str,
fallback: &'a str,
) -> &'a str {
existing
.get(name)
.map(String::as_str)
.filter(|value| !value.is_empty())
.unwrap_or(fallback)
}
impl From<ServeArgs> for Config {
fn from(args: ServeArgs) -> Self {
Config {
duckdb: args.duckdb,
init: args.init,
database: args.database,
quack_addr: args.quack_addr,
ready_timeout: Duration::from_secs(args.ready_timeout),
stop_timeout: Duration::from_secs(args.stop_timeout),
restart_delay: Duration::from_secs(1),
max_failures: args.max_failures.max(1),
}
}
}
fn init_logging(format: LogFormat) {
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
let builder = tracing_subscriber::fmt()
.with_env_filter(filter)
.with_writer(std::io::stderr);
match format {
LogFormat::Text => builder.init(),
LogFormat::Json => builder.json().init(),
}
}
/// Complete on SIGTERM or Ctrl-C.
async fn shutdown_signal() {
#[cfg(unix)]
{
use tokio::signal::unix::{SignalKind, signal};
match signal(SignalKind::terminate()) {
Ok(mut term) => {
tokio::select! {
_ = term.recv() => {}
_ = tokio::signal::ctrl_c() => {}
}
}
Err(error) => {
tracing::warn!(%error, "cannot listen for SIGTERM; only Ctrl-C stops hazine");
let _ = tokio::signal::ctrl_c().await;
}
}
}
#[cfg(not(unix))]
{
let _ = tokio::signal::ctrl_c().await;
}
tracing::info!("shutting down");
}
#[tokio::main]
async fn main() -> ExitCode {
let cli = Cli::parse();
init_logging(cli.log_format);
match cli.command {
Command::Serve(args) => match supervisor::run(args.into(), shutdown_signal()).await {
Ok(()) => ExitCode::SUCCESS,
Err(error) => {
tracing::error!(%error, "hazine failed");
ExitCode::FAILURE
}
},
Command::Setup(args) => match args.into_options().and_then(setup::run) {
Ok(()) => ExitCode::SUCCESS,
Err(error) => {
tracing::error!(%error, "setup failed");
ExitCode::FAILURE
}
},
Command::Ui(args) => match hazine::ui::run(args.into()).await {
Ok(()) => ExitCode::SUCCESS,
Err(error) => {
tracing::error!(%error, "hazine ui failed");
ExitCode::FAILURE
}
},
Command::Openalex(command) => {
let result = match command {
OpenalexCommand::Import {
entities,
threads,
memory_limit,
dry_run,
} => hazine::openalex::import(hazine::openalex::ImportOptions {
entities,
threads,
memory_limit,
dry_run,
}),
OpenalexCommand::Setup { release, dry_run } => {
hazine::openalex::setup(hazine::openalex::SetupOptions { release, dry_run })
}
};
match result {
Ok(()) => ExitCode::SUCCESS,
Err(error) => {
tracing::error!(%error, "hazine openalex failed");
ExitCode::FAILURE
}
}
}
Command::Ror(command) => {
// commonmeta's HTTP client is blocking: off the async runtime.
let result = tokio::task::spawn_blocking(move || match command {
RorCommand::Import {
force,
output,
dry_run,
} => hazine::ror::import(hazine::ror::ImportOptions {
force,
output,
dry_run,
}),
RorCommand::Setup { release, dry_run } => {
hazine::ror::setup(hazine::ror::SetupOptions { release, dry_run })
}
})
.await;
match result {
Ok(Ok(())) => ExitCode::SUCCESS,
Ok(Err(error)) => {
tracing::error!(%error, "hazine ror failed");
ExitCode::FAILURE
}
Err(error) => {
tracing::error!(%error, "hazine ror panicked");
ExitCode::FAILURE
}
}
}
Command::Orcid(command) => {
// Blocking: commonmeta's HTTP client, and the S3 uploads wait on
// the runtime from this thread.
let result = tokio::task::spawn_blocking(move || match command {
OrcidCommand::Import {
file,
force,
threads,
memory_limit,
output,
dry_run,
} => hazine::orcid::import(hazine::orcid::ImportOptions {
file,
force,
threads,
memory_limit,
output,
dry_run,
}),
OrcidCommand::Setup { release, dry_run } => {
hazine::orcid::setup(hazine::orcid::SetupOptions { release, dry_run })
}
})
.await;
match result {
Ok(Ok(())) => ExitCode::SUCCESS,
Ok(Err(error)) => {
tracing::error!(%error, "hazine orcid failed");
ExitCode::FAILURE
}
Err(error) => {
tracing::error!(%error, "hazine orcid panicked");
ExitCode::FAILURE
}
}
}
Command::Comet(command) => {
// Blocking: commonmeta's HTTP client, and the S3 uploads wait on
// the runtime from this thread.
let result = tokio::task::spawn_blocking(move || match command {
CometCommand::Import {
dir,
force,
threads,
memory_limit,
output,
dry_run,
} => hazine::comet::import(hazine::comet::ImportOptions {
dir,
force,
threads,
memory_limit,
output,
dry_run,
}),
CometCommand::Setup { release, dry_run } => {
hazine::comet::setup(hazine::comet::SetupOptions { release, dry_run })
}
})
.await;
match result {
Ok(Ok(())) => ExitCode::SUCCESS,
Ok(Err(error)) => {
tracing::error!(%error, "hazine comet failed");
ExitCode::FAILURE
}
Err(error) => {
tracing::error!(%error, "hazine comet panicked");
ExitCode::FAILURE
}
}
}
Command::Token { length } => match token::generate(length) {
Ok(token) => {
println!("{token}");
ExitCode::SUCCESS
}
Err(error) => {
eprintln!("error: generating a token: {error}");
ExitCode::FAILURE
}
},
}
}