Exemplo n.º 1
0
        /// <summary>
        /// Create a new instance of the command parser that matches the command name specified
        /// in the constructor.
        /// </summary>
        /// <returns>A new instance of the specified command parser that implements the
        /// <see cref="ICommandParser"/> interface.</returns>
        public ICommandParser GetCommandParser()
        {
            ICommandParser parser = (ICommandParser)CommandParsers[command];

            if (null == parser)
            {
                foreach (ICommandParser tp in AvailableCommands.Values)
                {
                    foreach (string nick in tp.Nicks)
                    {
                        if (nick.Equals(command))
                        {
                            parser = tp;
                        }
                    }
                    if (null != parser)
                    {
                        break;
                    }
                }
            }

            if (null == parser)
            {
                System.Console.WriteLine(String.Format("Command {0} not implemented.", command));
                System.Environment.Exit(-1);
            }

            parser.Args    = this.args;
            parser.CvsRoot = this.cvsRoot;
            parser.CurrentWorkingDirectory = this.workingDirectory;

            try {
                parser.ParseOptions();
            } catch (CommandLineParseException e) {
                string msg =
                    String.Format("{0}{1}{2}",
                                  e.Message, Environment.NewLine, parser.Usage);
                System.Console.WriteLine(msg);
            }

            return(parser);
        }