示例#1
0
        /// <summary>
        /// Main entry point which is directly called from main where nothing happens except exception catching.
        /// </summary>
        /// <param name="args"></param>
        public Renamer(string[] args)
        {
            // define parameterless command line switches.
            // Please note: Upper case characters define the shortcut name for each switch
            var switches = new Dictionary<string, Action>
            {
                {"RenameFiles", () => RenameFiles=true }, // shortcut -rf
            };

            // define command line switches which take one parameter
            var switchWithArg = new Dictionary<string, Action<string>>
            {
                {"Folder", (arg) => Folder = arg },  // shortcut -F
            };

            // Handler for <other arguments> if present
            Action<List<string>> rest = (parameters) => OtherArgs = parameters;

            ArgParser parser = new ArgParser(switches, switchWithArg, rest);

            // check if command line is well formed
            if (!parser.ParseArgs(args))
            {
                parser.PrintHelpWithMessages(HelpStr);
                return;
            }

            if (!ValidateArgs(parser))
            {
                // Display errors but not the help screen.
                parser.PrintHelpWithMessages(null);
            }
            else
            {
                // Ok we can start
                Run();
            }
        }