public void MakeCommandParserTest()
        {
            String[] args = { "--help" };
            // Test Creating a CommandLineParser object
            CommandLineParser newCommandLineParser = new CommandLineParser(args);

            Assert.IsNotNull(newCommandLineParser);
            LOGGER.Debug("Before parse execute for MakeCommandParserTest.");
            newCommandLineParser.Execute();
        }
        public void MinusDOptionConnectedToCvsRoot()
        {
            try {
                String[]          args   = { "-d :pserver:[email protected]:/cvsroot/sharpcvslib", "login" };
                CommandLineParser parser = new CommandLineParser(args);

                parser.Execute();
            } catch (Exception e) {
                Assert.Fail(string.Format("Should not have an exception.  Had: {0}", e.ToString()));
            }
            try {
                String[]          args   = { "-d:pserver:[email protected]:/cvsroot/sharpcvslib", "login" };
                CommandLineParser parser = new CommandLineParser(args);

                parser.Execute();
            } catch (Exception e) {
                Assert.Fail(string.Format("Should not have an exception.  Had: {0}", e.ToString()));
            }
        }
        public void ParseOptions()
        {
            String commandLine = "-d:pserver:[email protected]:/cvsroot/sharpcvslib co -r v0_3_1 -d newLocation sharpcvslib";

            String[]          args   = commandLine.Split(' ');
            CommandLineParser parser = new CommandLineParser(args);

            try {
                LOGGER.Debug("Before execute ParseOptions.");
                ICommand command = parser.Execute();

                Assert.IsTrue(command.GetType() == typeof(CheckoutModuleCommand));

                CheckoutModuleCommand co = (CheckoutModuleCommand)command;

                Assert.AreEqual("v0_3_1", co.Revision);
                Assert.AreEqual("newlocation", co.OverrideDirectory);
            }
            catch (Exception e) {
                LOGGER.Error(e);
                throw e;
            }
        }
Пример #4
0
        private void DoExecute() {
            string[] args = this._args;
            CommandLineParser parser = new CommandLineParser (args);

            ICommand command = null;
            try {
                command = parser.Execute ();
            } catch (CommandLineParseException e) {
                Writer.WriteLine(
                    String.Format("{0}{1}{2}",
                        Usage.General, Environment.NewLine, e.Message));
                return;
            } catch (Exception e) {
                ExitProgram("Exception parsing command.", e);
            }

            if (null != command) {
                // might need to move this up to the library, make working
                //  directory a public property??  Not sure.
                WorkingDirectory workingDirectory = parser.CurrentWorkingDirectory;

                string password = this.GetPassword(parser, workingDirectory);

                // Create CVSServerConnection object that has the ICommandConnection
                CVSServerConnection serverConn = new CVSServerConnection(workingDirectory);

                if (parser.Verbose) {
                    serverConn.RequestMessageEvent += 
                        new MessageEventHandler(Writer.WriteLine);
                    serverConn.ResponseMessageEvent += 
                        new MessageEventHandler(Writer.WriteLine);
                }

                serverConn.StartProcessEvent += 
                    new ProcessEventHandler(Writer.StartProcess);
                serverConn.StopProcessEvent += 
                    new ProcessEventHandler(Writer.StopProcess);
                serverConn.ResponseMessageEvents.UpdatedResponseMessageEvent += 
                    new MessageEventHandler(Writer.WriteLine);
                serverConn.ResponseMessageEvents.ClearStaticDirectoryResponseMessageEvent += 
                    new MessageEventHandler(Writer.WriteLine);
                serverConn.ResponseMessageEvents.SetStaticDirectoryResponseMessageEvent += 
                    new MessageEventHandler(Writer.WriteLine);
                serverConn.ResponseMessageEvents.ErrorResponseMessageEvent += 
                    new MessageEventHandler(Writer.WriteError);
                serverConn.ResponseMessageEvents.ListResponseMessageEvent +=
                    new MessageEventHandler(Writer.WriteLine);

                if (null == serverConn) {
                    string msg = "Unable to connect to server.";
                    ExitProgram(msg);
                }

                try{
                    // try connecting with empty password for anonymous users
                    serverConn.Connect(workingDirectory, password);
                } catch (AuthenticationException e){
                    string msg = String.Format("Fatal error, aborting.  cvs [login aborted]: {0}: unknown user or bad password.",
                        workingDirectory.CvsRoot.User);
                    ExitProgram(msg, e);
                } catch (Exception ex) {
                    string msg = String.Format("Fatal cvs error ( {0} ).",
                        ex.Message);
                    ExitProgram(msg, ex);
                }

                // Execute the command on cvs repository.
                command.Execute(serverConn);
                serverConn.Close();
            }
        }