Example #1
0
        /// <summary>
        /// Runs JsMrg.
        /// </summary>
        public ProgramRunnerExit Run()
        {
            var helpCheck = false;
            List <TerminalMessage> helpMessages = new List <TerminalMessage>();

            if (0 == Args.Length)
            {
                helpCheck = true;
                HelpCheck(out helpMessages, true);
            }

            if (helpCheck || CheckResult.Apply == HelpCheck(out helpMessages))
            {
                TerminalWriter.WriteTerminalMessages(helpMessages);

                return(ProgramRunnerExit.Help);
            }

            OutputStartupMessages();

            // If help is not requested, we are expecting exactly two parameters.
            if (2 != Args.Length)
            {
                var tm = TerminalMessage.Create(TerminalMessages.UnexpectedNumberOfParams, Color.Red);
                TerminalWriter.WriteTerminalMessage(tm);

                return(ProgramRunnerExit.Error);
            }

            InputFile  = Args[0];
            InputFile  = IoHelper.OptionalAdjustmentToAbsolutPath(InputFile);
            OutputFile = Args[1];

            if (CheckResult.Ok != IoCheck(out var terminalMessages))
            {
                TerminalWriter.WriteTerminalMessages(terminalMessages);

                // Bail out, we are not ready to run.
                return(ProgramRunnerExit.IoCheckOut);
            }

            var jsMrgRunner = new JsMrgRunner();
            var runResult   = jsMrgRunner.Run(InputFile, OutputFile, out var combinedRunMessages);
            var runExit     = ProgramRunnerExit.Done;

            if (false == runResult)
            {
                var tm = TerminalMessage.Create(TerminalMessages.JsMrgRunEndedWErrors, Color.Red);
                TerminalWriter.WriteTerminalMessage(tm);

                runExit = ProgramRunnerExit.Error;
            }

            TerminalWriter.WriteTerminalMessages(combinedRunMessages);
            if (runExit == ProgramRunnerExit.Done)
            {
                JsMrgOutput = jsMrgRunner.ResultingFileContent;
            }

            return(runExit);
        }
Example #2
0
 public JsmrgException(TerminalMessage terminalMessage, string excMessage) : base(excMessage)
 {
     TerminalWriter.WriteTerminalMessage(terminalMessage);
 }