| 23 | SC::Console* globalConsole; |
| 24 | |
| 25 | int main(int argc, const char* argv[]) |
| 26 | { |
| 27 | using namespace SC; |
| 28 | using namespace SC::Tools; |
| 29 | Console::tryAttachingToParentConsole(); |
| 30 | Console console; |
| 31 | |
| 32 | Tool::Arguments arguments{console}; |
| 33 | |
| 34 | globalConsole = &console; |
| 35 | |
| 36 | if (argc < 5) |
| 37 | { |
| 38 | console.printLine( |
| 39 | "Usage: ${TOOL} libraryDirectory toolSource toolDestination projectDirectory [tool] [action]"); |
| 40 | return -1; |
| 41 | } |
| 42 | int numArguments = 0; |
| 43 | |
| 44 | // TODO: It could be worth cleanup and move command-line utf handling somewhere it could be reused |
| 45 | #if SC_PLATFORM_WINDOWS |
| 46 | wchar_t* const* nativeArgs = nullptr; |
| 47 | (void)(argc); |
| 48 | (void)(argv); |
| 49 | LPWSTR* args = ::CommandLineToArgvW(::GetCommandLineW(), &numArguments); |
| 50 | if (args == nullptr) |
| 51 | { |
| 52 | console.printLine("Failed parsing command line"); |
| 53 | return -1; |
| 54 | } |
| 55 | auto freeDefer = [args]() { ::LocalFree(args); }; |
| 56 | nativeArgs = args; |
| 57 | #else |
| 58 | const char** nativeArgs = nullptr; |
| 59 | nativeArgs = argv; |
| 60 | numArguments = argc; |
| 61 | #endif |
| 62 | const StringView libraryDirectory = StringView::fromNullTerminated(nativeArgs[1], StringEncoding::Native); |
| 63 | const StringView toolSource = StringView::fromNullTerminated(nativeArgs[2], StringEncoding::Native); |
| 64 | const StringView toolDestination = StringView::fromNullTerminated(nativeArgs[3], StringEncoding::Native); |
| 65 | const StringView projectDirectory = StringView::fromNullTerminated(nativeArgs[4], StringEncoding::Native); |
| 66 | |
| 67 | { |
| 68 | (void)Path::normalize(arguments.libraryDirectory, libraryDirectory, Path::Type::AsNative); |
| 69 | (void)Path::normalize(arguments.toolSource, toolSource, Path::Type::AsNative); |
| 70 | (void)Path::normalize(arguments.toolDestination, toolDestination, Path::Type::AsNative); |
| 71 | (void)Path::normalize(arguments.projectDirectory, projectDirectory, Path::Type::AsNative); |
| 72 | } |
| 73 | |
| 74 | arguments.tool = Tool::getToolName(); |
| 75 | |
| 76 | if (numArguments > 6) |
| 77 | { |
| 78 | arguments.action = StringView::fromNullTerminated(argv[6], StringEncoding::Ascii); |
| 79 | } |
| 80 | else |
| 81 | { |
| 82 | arguments.action = Tool::getDefaultAction(); |
nothing calls this directly
no test coverage detected