/// <summary>
        /// Tries to parse a command line.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="commandLine">The command line.</param>
        /// <param name="to">To.</param>
        /// <returns></returns>
        public static bool TryParseCommandLine <T>(string commandLine, out T to)
            where T : class, new()
        {
            if (commandLine == null)
            {
                throw new ArgumentNullException("commandLine");
            }

            return(CommandLineTokenizer <T> .TryParse(GetCommandlineWords(commandLine), new TokenizerArgs(), out to));
        }
Beispiel #2
0
        public void ParseEmptySpaces()
        {
            // Arrange
            var subject = new CommandLineTokenizer();

            // Act
            var result = subject.ToTokens("         ");

            // Assert
            Assert.True(result.Count == 0);
        }
        /// <summary>
        /// Tries to parse a command line.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="commandLineArguments">The command line arguments.</param>
        /// <param name="to">To.</param>
        /// <returns></returns>
        public static bool TryParseCommandLine <T>(IList <string> commandLineArguments, out T to)
            where T : class, new()
        {
            if (commandLineArguments == null)
            {
                throw new ArgumentNullException("args");
            }

            EnsureItems(commandLineArguments, "commandLineArguments");

            return(CommandLineTokenizer <T> .TryParse(commandLineArguments, new TokenizerArgs(), out to));
        }
Beispiel #4
0
        public void IgnoreSpaces1()
        {
            // Arrange
            var subject = new CommandLineTokenizer();

            // Act
            var result = subject.ToTokens("   word1   ");

            // Assert
            Assert.True(result.Count == 1);
            Assert.True(result[0] == "word1");
        }
Beispiel #5
0
        public void TreatWeirdScenario1()
        {
            // Arrange
            var subject = new CommandLineTokenizer();

            // Act
            var result = subject.ToTokens("   word1\"\"word2");

            // Assert
            Assert.True(result.Count == 1);
            Assert.True(result[0] == "word1word2");
        }
Beispiel #6
0
        public void TreatNewlineLikeSpaces()
        {
            // Arrange
            var subject = new CommandLineTokenizer();

            // Act
            var result = subject.ToTokens("word1\nword2");

            // Assert
            Assert.True(result.Count == 2);
            Assert.True(result[0] == "word1");
            Assert.True(result[1] == "word2");
        }
Beispiel #7
0
        public void ParseTwoItems()
        {
            // Arrange
            var subject = new CommandLineTokenizer();

            // Act
            var result = subject.ToTokens("word1 word2");

            // Assert
            Assert.True(result.Count == 2);
            Assert.True(result[0] == "word1");
            Assert.True(result[1] == "word2");
        }
Beispiel #8
0
        public void RespectQuotes()
        {
            // Arrange
            var subject = new CommandLineTokenizer();

            // Act
            var result = subject.ToTokens("   word1 \"  word2   \" ");

            // Assert
            Assert.True(result.Count == 2);
            Assert.True(result[0] == "word1");
            Assert.True(result[1] == "  word2   ");
        }
Beispiel #9
0
        public void TreatCarriageReturnNewlineAsSpace()
        {
            // Arrange
            var subject = new CommandLineTokenizer();

            // Act
            var result = subject.ToTokens("   word1 \r\n  word2   ");

            // Assert
            Assert.True(result.Count == 2);
            Assert.True(result[0] == "word1");
            Assert.True(result[1] == "word2");
        }
Beispiel #10
0
 internal Program(IEnumerable<string> args)
 {
   _commandLine = new CommandLineTokenizer(args);
 }