static int Main(string[] args)
        {
            string[] commandArguments;
            var      commandName = ExtractCommand(args, out commandArguments);
            var      locator     = new CommandLocator();
            var      command     = locator.Find(commandName);

            if (command == null)
            {
                locator.Create(locator.Find("help")).Execute(commandArguments);
                return(4);
            }

            try
            {
                var exitCode = locator.Create(command).Execute(commandArguments);
                return(exitCode);
            }
            catch (OptionException ex)
            {
                WriteError(ex);
                locator.Create(locator.Find("help")).Execute(new[] { commandName });
                return(4);
            }
            catch (ArgumentException ex)
            {
                WriteError(ex);
                return(4);
            }
            catch (FileNotFoundException ex)
            {
                WriteError(ex);
                return(4);
            }
            catch (InvalidDataException ex)
            {
                WriteError(ex);
                return(2);
            }
            catch (IOException ex)
            {
                WriteError(ex, details: true);
                return(1);
            }
            catch (Exception ex)
            {
                WriteError(ex, details: true);
                return(3);
            }
        }
Example #2
0
        private static MemoryStream ConstructOctodiffCmd(string cmdName, string[] args, MemoryStream ms = null)
        {
            // Setup Octodiff command
            var          sb        = new StringBuilder();
            var          cl        = new CommandLocator();
            var          command   = cl.Find(cmdName);
            MemoryStream sigStream = null;

            // Parse commands
            foreach (string arg in args)
            {
                sb.Append(arg != "" ? arg + " " : "");
            }

            try
            {
                // Execute octodiff command
                Log.Info("Octodiff --" + cmdName + " " + sb.ToString());
                sigStream = cl.Create(command).Execute(args, ms);

                return(sigStream);
            }
            catch (OptionException ex)
            {
                Log.Error(new Error(ex, "Octodiff exception"));
            }
            catch (UsageException ex)
            {
                Log.Error(new Error(ex, "Octodiff exception"));
            }
            catch (FileNotFoundException ex)
            {
                Log.Error(new Error(ex, "Octodiff exception"));
            }
            catch (CorruptFileFormatException ex)
            {
                Log.Error(new Error(ex, "Octodiff exception"));
            }
            catch (IOException ex)
            {
                Log.Error(new Error(ex, "Octodiff exception"));
            }
            catch (Exception ex)
            {
                Log.Error(new Error(ex, "Octodiff exception"));
            }

            return(null);
        }