示例#1
0
        public static int Main(params String[] args)
        {
            var errors     = new List <String> ();
            var parameters = new Parameters()
            {
                CraftFilter = new RegexFilter(""),
                PartFilter  = new RegexFilter("")
            };

            var ui = new ProgramUI(parameters);
            var printInfoHeader = new Info(ui);
            var printUsage      = new Help(ui);

            var commandLineParser = new CommandLineParser()
                                    .RequiredArgument(0, cmd => parameters.Command = ParseCommand(cmd, ui, parameters))
                                    .RequiredSwitchArg <String> ("i", filePath => parameters.InputFilePath       = filePath)
                                    .OptionalSwitchArg <String> ("o", filePath => parameters.OutputFilePath      = filePath)
                                    .OptionalSwitchArg <String> ("c", "craft", pattern => parameters.CraftFilter = new RegexFilter(pattern))
                                    .OptionalSwitchArg <String> ("p", "part", pattern => parameters.PartFilter   = new RegexFilter(pattern))
                                    .OptionalSwitch("s", "silent", () => parameters.SilentExecution = true)
                                    .OnError(errors.Add);

            try {
                commandLineParser.Parse(args);

                if (parameters.OutputFilePath == null)
                {
                    parameters.OutputFilePath = parameters.InputFilePath;
                }

                if (errors.Count > 0)
                {
                    printInfoHeader.Execute();
                    printUsage.Execute();
                    errors.ForEach(ui.DisplayErrorMessage);
                    return(-1);
                }

                if (!parameters.SilentExecution)
                {
                    printInfoHeader.Execute();
                }

                return(parameters.Command());
            } catch (Exception ex) {
                ui.DisplayErrorMessage(ex.ToString());
                return(-1);
            }
        }
示例#2
0
        public static int Main (params String[] args)
        {
            var errors = new List<String> ();
            var parameters = new Parameters () {
                CraftFilter = new RegexFilter (""),
                PartFilter = new RegexFilter ("")
            };

            var ui = new ProgramUI (parameters);
            var printInfoHeader = new Info (ui);
            var printUsage = new Help (ui);

            var commandLineParser = new CommandLineParser ()
                .RequiredArgument (0, cmd => parameters.Command = ParseCommand (cmd, ui, parameters))
                .RequiredSwitchArg<String> ("i", filePath => parameters.InputFilePath = filePath)
                .OptionalSwitchArg<String> ("o", filePath => parameters.OutputFilePath = filePath)
                .OptionalSwitchArg<String> ("c", "craft", pattern => parameters.CraftFilter = new RegexFilter (pattern))
                .OptionalSwitchArg<String> ("p", "part", pattern => parameters.PartFilter = new RegexFilter (pattern))
                .OptionalSwitch ("s", "silent", () => parameters.SilentExecution = true)
                .OnError (errors.Add);
            
            try {
                commandLineParser.Parse (args);

                if (parameters.OutputFilePath == null) {
                    parameters.OutputFilePath = parameters.InputFilePath;
                }

                if (errors.Count > 0) {
                    printInfoHeader.Execute ();
                    printUsage.Execute ();
                    errors.ForEach (ui.DisplayErrorMessage);
                    return -1;
                }

                if (!parameters.SilentExecution)
                    printInfoHeader.Execute ();

                return parameters.Command ();
            } catch (Exception ex) {
                ui.DisplayErrorMessage (ex.ToString ());
                return -1;
            }
        }