public static int Main(string[] args) { // No arguments = open gui with no project (or just exit for now) if (args.Length == 0) { CConsole.Error("The GUI for Prism is not yet complete. Please use the command line interface for now."); CConsole.Error(" Usage: Prism.exe <action> <file> [args]"); return(-1); } // Convert all of the flags to lower case and normalizes the first character args = ArgParser.Sanitize(args); // Check for the help flag if (ArgParser.Help(args)) { PrintHelp(); return(0); } // If we want verbose bool verbose = ArgParser.Verbose(args); // Check for a valid action if (!GetAction(args, out string action)) { CConsole.Error($"The action '{action}' is not valid. Please use one of: {String.Join(", ", VALID_ACTIONS)}."); return(-1); } // Make sure there are enough arguments if (args.Length < 2) { CConsole.Error("Not enough command line arguments specified."); return(-1); } // Dispatch the action to the proper handler switch (action) { case "new": return(NewFile.Create(args, verbose)); case "build": case "rebuild": case "clean": return(CommandLineAction.RunAction(action, args, verbose)); case "view": return(ViewProject.Summarize(args, verbose)); default: CConsole.Error($"The action '{action}' is not yet implemented."); return(-1); } }
// Runs the action passed, with the original command line arguments tacked on (path should be args[1]) public static int RunAction(string action, string[] args, bool verbose) { // Try to load the content project file string filePath = args[1]; ContentProject project = null; try { // Check for any parameter override cmd line args var oargs = ArgParser.Params(args); project = ContentProject.LoadFromFile(filePath, oargs); } catch (Exception e) { CConsole.Error($"Could not load content project file, reason: {e.Message}."); if (verbose && (e.InnerException != null)) { CConsole.Error($"{e.InnerException.GetType().Name}"); CConsole.Error(e.InnerException.StackTrace); } return(-1); } // Report project information if (verbose) { CConsole.Info($" ------ Project Info ------ "); CConsole.Info($" Content Root: {project.Paths.ContentRoot}"); CConsole.Info($" Intermediate Root: {project.Paths.IntermediateRoot}"); CConsole.Info($" Output Root: {project.Paths.OutputRoot}"); } // Get the parallelization info uint threadCount = (action == "clean") ? 1 : ArgParser.Parallel(args); if (threadCount > 1) { CConsole.Info($"Using {threadCount} threads for {action} process."); } // Create the build engine to manage this action BuildEngine engine = null; bool useStats = ArgParser.Stats(args); try { engine = new BuildEngine(project, new CommandLineLogger(verbose, useStats), threadCount); } catch (Exception e) { CConsole.Error($"Unable to create build engine, reason: {e.Message}."); if (verbose) { CConsole.Error($"{e.GetType().Name}"); CConsole.Error(e.StackTrace); } return(-1); } // Get the build type bool releaseBuild = ArgParser.Release(args); // Start the action task and logging using (engine) { try { // Launch the correct task Task task = null; switch (action) { case "build": task = engine.Build(false, releaseBuild, useStats); break; case "rebuild": task = engine.Build(true, releaseBuild, useStats); break; case "clean": task = engine.Clean(); break; default: CConsole.Error($"The action '{action}' was not understood."); return(-1); // Should never be reached } task.Start(); // Wait for the task to finish, logging while we go while (!task.IsCompleted) { Thread.Sleep(50); engine.Logger.Poll(); } // Check that the task did not encounter an exception if (task.IsFaulted) { var te = task.Exception.InnerException; CConsole.Error($"Action '{action}' encountered an exception, message: {te?.Message}."); if (verbose) { CConsole.Error($"{te?.GetType().Name}"); CConsole.Error(te?.StackTrace); } return(-1); } } catch (Exception e) { CConsole.Error($"Unhandled exception during action '{action}', message: {e.Message}."); if (verbose) { CConsole.Error($"{e.GetType().Name}"); CConsole.Error(e.StackTrace); } return(-1); } } // Everything went well return(0); }