From 0cd5edc287298a7cfb560709388ed9f0d1b0f44c Mon Sep 17 00:00:00 2001 From: Ketasaja Date: Tue, 30 Jul 2024 20:41:25 +0000 Subject: [PATCH] Add version output to CLI --- CLI/Analyze.cpp | 6 ++++++ CLI/Ast.cpp | 6 ++++++ CLI/Bytecode.cpp | 6 ++++++ CLI/Compile.cpp | 7 +++++++ CLI/Reduce.cpp | 4 ++++ CLI/Repl.cpp | 7 +++++++ Common/include/Luau/Common.h | 2 ++ 7 files changed, 38 insertions(+) diff --git a/CLI/Analyze.cpp b/CLI/Analyze.cpp index 911d2ad65..d08fc04e3 100644 --- a/CLI/Analyze.cpp +++ b/CLI/Analyze.cpp @@ -115,6 +115,7 @@ static bool reportModuleResult(Luau::Frontend& frontend, const Luau::ModuleName& static void displayHelp(const char* argv0) { + printf("%s\n", LUAU_VERSION); printf("Usage: %s [--mode] [options] [file list]\n", argv0); printf("\n"); printf("Available modes:\n"); @@ -304,6 +305,11 @@ int main(int argc, char** argv) return 0; } + if (argc >= 2 && (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)) { + printf("%s\n", LUAU_VERSION); + return 0; + } + ReportFormat format = ReportFormat::Default; Luau::Mode mode = Luau::Mode::Nonstrict; bool annotate = false; diff --git a/CLI/Ast.cpp b/CLI/Ast.cpp index b5a922aaa..4d09baea5 100644 --- a/CLI/Ast.cpp +++ b/CLI/Ast.cpp @@ -12,6 +12,7 @@ static void displayHelp(const char* argv0) { + printf("%s\n", LUAU_VERSION); printf("Usage: %s [file]\n", argv0); } @@ -34,6 +35,11 @@ int main(int argc, char** argv) displayHelp(argv[0]); return 0; } + else if (argc >= 2 && (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)) + { + printf("%s\n", LUAU_VERSION); + return 0; + } else if (argc < 2) { displayHelp(argv[0]); diff --git a/CLI/Bytecode.cpp b/CLI/Bytecode.cpp index 02ef3237b..f1ceb9770 100644 --- a/CLI/Bytecode.cpp +++ b/CLI/Bytecode.cpp @@ -32,10 +32,12 @@ static Luau::CompileOptions copts() static void displayHelp(const char* argv0) { + printf("%s\n", LUAU_VERSION); printf("Usage: %s [options] [file list]\n", argv0); printf("\n"); printf("Available options:\n"); printf(" -h, --help: Display this usage message.\n"); + printf(" -v, --version: Display Luau version."); printf(" -O: compile with optimization level n (default 1, n should be between 0 and 2).\n"); printf(" -g: compile with debug level n (default 1, n should be between 0 and 2).\n"); printf(" --fflags=: flags to be enabled.\n"); @@ -52,6 +54,10 @@ static bool parseArgs(int argc, char** argv, std::string& summaryFile) { displayHelp(argv[0]); } + else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) + { + printf("%s\n", LUAU_VERSION); + } else if (strncmp(argv[i], "-O", 2) == 0) { int level = atoi(argv[i] + 2); diff --git a/CLI/Compile.cpp b/CLI/Compile.cpp index dd6b14abb..89170456d 100644 --- a/CLI/Compile.cpp +++ b/CLI/Compile.cpp @@ -402,6 +402,7 @@ static bool compileFile(const char* name, CompileFormat format, Luau::CodeGen::A static void displayHelp(const char* argv0) { + printf("%s\n", LUAU_VERSION); printf("Usage: %s [--mode] [options] [file list]\n", argv0); printf("\n"); printf("Available modes:\n"); @@ -409,6 +410,7 @@ static void displayHelp(const char* argv0) printf("\n"); printf("Available options:\n"); printf(" -h, --help: Display this usage message.\n"); + printf(" -v, --version: Display version.\n"); printf(" -O: compile with optimization level n (default 1, n should be between 0 and 2).\n"); printf(" -g: compile with debug level n (default 1, n should be between 0 and 2).\n"); printf(" --target=: compile code for specific architecture (a64, x64, a64_nf, x64_ms).\n"); @@ -470,6 +472,11 @@ int main(int argc, char** argv) displayHelp(argv[0]); return 0; } + else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) + { + printf("%s\n", LUAU_VERSION); + return 0; + } else if (strncmp(argv[i], "-O", 2) == 0) { int level = atoi(argv[i] + 2); diff --git a/CLI/Reduce.cpp b/CLI/Reduce.cpp index 4b41fc76e..4dcab0a23 100644 --- a/CLI/Reduce.cpp +++ b/CLI/Reduce.cpp @@ -470,6 +470,7 @@ struct Reducer [[noreturn]] void help(const std::vector& args) { + printf("%s\n", LUAU_VERSION); printf("Syntax: %s script command \"search text\"\n", args[0].data()); printf(" Within command, use {} as a stand-in for the script being reduced\n"); exit(1); @@ -482,6 +483,9 @@ int main(int argc, char** argv) if (args.size() != 4) help(args); + if (args[1] == "-v" || args[1] == "--version") + printf("%s\n", LUAU_VERSION); + for (size_t i = 1; i < args.size(); ++i) { if (args[i] == "--help") diff --git a/CLI/Repl.cpp b/CLI/Repl.cpp index 814d7c8c9..be855ec0a 100644 --- a/CLI/Repl.cpp +++ b/CLI/Repl.cpp @@ -656,6 +656,7 @@ static bool runFile(const char* name, lua_State* GL, bool repl) static void displayHelp(const char* argv0) { + printf("%s\n", LUAU_VERSION); printf("Usage: %s [options] [file list] [-a] [arg list]\n", argv0); printf("\n"); printf("When file list is omitted, an interactive REPL is started instead.\n"); @@ -664,6 +665,7 @@ static void displayHelp(const char* argv0) printf(" --coverage: collect code coverage while running the code and output results to coverage.out\n"); printf(" -h, --help: Display this usage message.\n"); printf(" -i, --interactive: Run an interactive REPL after executing the last script specified.\n"); + printf(" -v, --version: Display version.\n"); printf(" -O: compile with optimization level n (default 1, n should be between 0 and 2).\n"); printf(" -g: compile with debug level n (default 1, n should be between 0 and 2).\n"); printf(" --profile[=N]: profile the code using N Hz sampling (default 10000) and output results to profile.out\n"); @@ -705,6 +707,11 @@ int replMain(int argc, char** argv) { interactive = true; } + else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) + { + printf("%s\n", LUAU_VERSION); + return 0; + } else if (strncmp(argv[i], "-O", 2) == 0) { int level = atoi(argv[i] + 2); diff --git a/Common/include/Luau/Common.h b/Common/include/Luau/Common.h index 406f6553c..3e3f55a55 100644 --- a/Common/include/Luau/Common.h +++ b/Common/include/Luau/Common.h @@ -1,6 +1,8 @@ // This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details #pragma once +#define LUAU_VERSION "Luau 0.636" + // Compiler codegen control macros #ifdef _MSC_VER #define LUAU_NORETURN __declspec(noreturn)