예제 #1
0
        internal IEnumerable<string[]> Parse(Notification note)
        {
            var parsed = new List<string[]>();

            var length = _commandLineArguments.Count();

            for (var i = 0; i < length; i++)
            {
                var fst = _commandLineArguments.ElementAt(i);
                var snd = i < length - 1 ? _commandLineArguments.ElementAt(i + 1) : _commandLineArguments.ElementAt(0);
                var sndIsCmd = IsCommand(snd);

                string cmd;

                if (TryParseCommand(fst, out cmd))
                {
                    var value = sndIsCmd
                        ? String.Empty
                        : snd;

                    parsed.Add(new[] { cmd, value });
                    continue;
                }

                if (sndIsCmd)
                    continue;

                note.AddError(String.Format("Expected a command but got \'{0}\'.", i == 0 ? fst : snd));
                break;
            }

            return parsed;
        }
예제 #2
0
 private void CheckAllRequired(IEnumerable<string[]> args, Notification note)
 {
     foreach (var arg in _requiredCommands.Where(x => !args.Select(arg => arg.First()).Contains(x)))
     {
         note.AddError(String.Format("Required command \'{0}\' not in argument list.", arg));
     }
 }
예제 #3
0
        private void CheckNoDuplicates(IEnumerable<string[]> args, Notification note)
        {
            var duplicates = args
                .Where(x => _definedCommands.Contains(x.First()))
                .GroupBy(x => x.First())
                .Where(x => x.Count() > 1)
                .Select(x => x.Key)
                .Distinct();

            foreach (var duplicate in duplicates)
            {
                note.AddError(String.Format("Duplicate command \'{0}\'.", duplicate));
            }
        }
예제 #4
0
 private void CheckAllDefined(IEnumerable<string[]> args, Notification note)
 {
     foreach (var arg in args.Select(x => x.First()).Distinct().Where(arg => !_definedCommands.Contains(arg)))
     {
         note.AddError(String.Format("Command \'{0}\' not defined.", arg));
     }
 }