Add version as a flag (#4507)

This commit is contained in:
Stefan Stanciulescu 2022-02-17 12:02:46 +01:00 committed by GitHub
parent b8b2737890
commit f169a9be3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -104,6 +104,7 @@ fn main() -> Result<()> {
|| arg == "--config-file" || arg == "--config-file"
|| arg == "--perf" || arg == "--perf"
|| arg == "--threads" || arg == "--threads"
|| arg == "--version"
{ {
collect_arg_nushell = true; collect_arg_nushell = true;
} }
@ -292,6 +293,16 @@ fn parse_commandline_args(
std::process::exit(1); std::process::exit(1);
} }
if call.has_flag("version") {
let _ = std::panic::catch_unwind(move || {
let stdout = std::io::stdout();
let mut stdout = stdout.lock();
let _ = stdout.write_all(env!("CARGO_PKG_VERSION").to_string().as_bytes());
});
std::process::exit(0);
}
return Ok(NushellCliArgs { return Ok(NushellCliArgs {
redirect_stdin, redirect_stdin,
login_shell, login_shell,
@ -335,6 +346,7 @@ impl Command for Nu {
.switch("stdin", "redirect the stdin", None) .switch("stdin", "redirect the stdin", None)
.switch("login", "start as a login shell", Some('l')) .switch("login", "start as a login shell", Some('l'))
.switch("interactive", "start as an interactive shell", Some('i')) .switch("interactive", "start as an interactive shell", Some('i'))
.switch("version", "print the version", Some('v'))
.switch( .switch(
"perf", "perf",
"start and print performance metrics during startup", "start and print performance metrics during startup",