Skip to content

Commit

Permalink
Add version output to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Ketasaja committed Jul 30, 2024
1 parent 58f8c24 commit 0cd5edc
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CLI/Analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions CLI/Ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

static void displayHelp(const char* argv0)
{
printf("%s\n", LUAU_VERSION);
printf("Usage: %s [file]\n", argv0);
}

Expand All @@ -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]);
Expand Down
6 changes: 6 additions & 0 deletions CLI/Bytecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<n>: compile with optimization level n (default 1, n should be between 0 and 2).\n");
printf(" -g<n>: compile with debug level n (default 1, n should be between 0 and 2).\n");
printf(" --fflags=<fflags>: flags to be enabled.\n");
Expand All @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions CLI/Compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,15 @@ 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");
printf(" binary, text, remarks, codegen\n");
printf("\n");
printf("Available options:\n");
printf(" -h, --help: Display this usage message.\n");
printf(" -v, --version: Display version.\n");
printf(" -O<n>: compile with optimization level n (default 1, n should be between 0 and 2).\n");
printf(" -g<n>: compile with debug level n (default 1, n should be between 0 and 2).\n");
printf(" --target=<target>: compile code for specific architecture (a64, x64, a64_nf, x64_ms).\n");
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions CLI/Reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ struct Reducer

[[noreturn]] void help(const std::vector<std::string_view>& 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);
Expand All @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions CLI/Repl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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<n>: compile with optimization level n (default 1, n should be between 0 and 2).\n");
printf(" -g<n>: 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");
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions Common/include/Luau/Common.h
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 0cd5edc

Please sign in to comment.