Add version command

This commit is contained in:
2025-06-25 20:04:33 +10:00
parent 82726ebb5d
commit 7ec60f0e6e
4 changed files with 619 additions and 14 deletions

View File

@@ -30,8 +30,11 @@ fn panic_cb(panic: &panic::PanicHookInfo) {
eprintln!(
"{}",
"This is a bug in luby. Please kindly report this at https://git.lua.re/luaneko/luby."
.yellow()
format_args!(
"This is a bug in luby. Please kindly report this at {}.",
env!("CARGO_PKG_REPOSITORY")
)
.yellow()
);
}
@@ -45,7 +48,7 @@ struct Args {
#[clap(long, short = 'e', value_name = "CHUNK")]
eval: Vec<String>,
/// Libraries to require on startup.
/// Libraries to require.
#[clap(long, short = 'l', value_name = "NAME")]
lib: Vec<String>,
@@ -54,29 +57,45 @@ struct Args {
log: tracing::Level,
/// LuaJIT control commands.
#[clap(long, short = 'j', value_name = "CMD=FLAGS")]
#[clap(long, short = 'j', help_heading = "Runtime", value_name = "CMD=FLAGS")]
jit: Vec<String>,
/// Number of tokio worker threads.
#[clap(long, value_name = "THREADS", default_value_t = Self::threads())]
/// Number of worker threads.
#[clap(
long,
short = 'T',
help_heading = "Runtime",
value_name = "THREADS",
default_value_t = Self::threads()
)]
threads: NonZero<usize>,
/// Number of tokio blocking threads.
#[clap(long, value_name = "THREADS", default_value_t = Self::blocking_threads())]
/// Number of blocking threads.
#[clap(
long,
help_heading = "Runtime",
value_name = "THREADS",
default_value_t = Self::blocking_threads()
)]
blocking_threads: NonZero<usize>,
/// Enable tokio-console integration.
#[clap(long)]
#[clap(long, help_heading = "Debugging")]
enable_console: bool,
/// tokio-console publish address.
#[clap(
long,
help_heading = "Debugging",
value_name = "ADDRESS",
default_value = "127.0.0.1:6669",
requires = "enable_console"
)]
console_addr: SocketAddr,
/// Print version.
#[clap(long, short = 'V')]
version: bool,
}
impl Args {
@@ -100,6 +119,10 @@ fn main() -> Result<(), ExitCode> {
panic::set_hook(Box::new(panic_cb));
let args = Args::parse();
if args.version {
return Ok(print_version());
}
init_logger(&args);
let tokio = init_tokio(&args);
@@ -112,6 +135,18 @@ fn main() -> Result<(), ExitCode> {
})
}
fn print_version() {
println!("luby {}", env!("VERGEN_GIT_DESCRIBE"));
println!("{}\n", env!("CARGO_PKG_HOMEPAGE"));
println!("Compiled with {} -- {}", luajit::version(), luajit::url());
println!(
"Compiled with rustc {} on {} for {}",
env!("VERGEN_RUSTC_SEMVER"),
env!("VERGEN_RUSTC_HOST_TRIPLE"),
env!("VERGEN_CARGO_TARGET_TRIPLE"),
);
}
fn init_logger(args: &Args) {
use tracing::level_filters::LevelFilter;
use tracing_subscriber::{Layer, util::*};