Example #1
0
            public IOptionResult <T> RunOption()
            {
                IOptionResult <T> result = _self.RunOption();

                _action(result);
                return(result);
            }
Example #2
0
 public MyOptionsArray(IRosskoRepository repository, IValidate validator,
                       IJsonResult jsonResult, IOptionResult optionResult)
 {
     this.repository   = repository;
     this.validator    = validator;
     this.jsonResult   = jsonResult;
     this.optionResult = optionResult;
 }
            public IOptionResult <T> Run()
            {
                IOptionResult <T> result = _self.Run();

                if (!result.IsNone)
                {
                    return(result);
                }
                return(_selector().Run());
            }
Example #4
0
            public IOptionResult <TResult> RunOption()
            {
                IOptionResult <T> result = _self.RunOption();

                if (!result.IsNone)
                {
                    return(new JustResult <TResult>(_selector(result.Value)));
                }
                return(NoneResult <TResult> .Default);
            }
            public IOptionResult <T> RunOption()
            {
                IOptionResult <T> result = _self.RunOption();

                if (result.IsNone)
                {
                    _action();
                }
                return(result);
            }
Example #6
0
            public IOptionResult <TResult> RunOption()
            {
                IOptionResult <TFirst>  selfResult   = _self.RunOption();
                IOptionResult <TSecond> secondResult = _second.RunOption();

                if (!selfResult.IsNone && !secondResult.IsNone)
                {
                    return(new JustResult <TResult>(_resultSelector(selfResult.Value, secondResult.Value)));
                }
                return(NoneResult <TResult> .Default);
            }
Example #7
0
        public static void Execute <T>(this IOptionMonad <T> self)
        {
            IOptionResult <T> selfResult = self.RunOption();

            if (selfResult.IsNone)
            {
                return;
            }
            else
            {
                return;
            }
        }
Example #8
0
            public IOptionResult <T> RunOption()
            {
                IOptionResult <T> result = _self.RunOption();

                if (_selector(result))
                {
                    return(result);
                }
                else
                {
                    return(NoneResult <T> .Default);
                }
            }
Example #9
0
            public IOptionResult <T> RunOption()
            {
                IOptionResult <T> result = _self.RunOption();

                if (_selector(result))
                {
                    return(result);
                }
                else
                {
                    return(_elseSource.RunOption());
                }
            }
Example #10
0
        public static void Execute <T>(this IOptionMonad <T> self, Action <T> onJust)
        {
            IOptionResult <T> selfResult = self.RunOption();

            if (selfResult.IsNone)
            {
                return;
            }
            else
            {
                onJust(selfResult.Value);
                return;
            }
        }
Example #11
0
        private void ParseOptionArgument(Token token, IOptionResult option, IList arguments)
        {
            if (token.Type != TokenType.OptionArgument)
            {
                throw new ArgumentException(nameof(token));
            }
            if (option == null)
            {
                throw new ArgumentNullException(nameof(option));
            }
            if (option.IsCompleted)
            {
                throw new ArgumentException(nameof(option));
            }

            if (!option.AcceptMoreArguments)
            {
                option.Argument = token.Value;
            }
            else
            {
                arguments.Add(token.Value);
            }
        }
Example #12
0
        /// <summary>
        /// Parses the command line arguments.
        /// </summary>
        /// <param name="definitions">A collection of command line arguments.</param>
        /// <param name="args"></param>
        /// <returns></returns>
        public ParserResult Parse(IEnumerable <IDefinition> definitions, String[] args)
        {
            if (definitions == null)
            {
                throw new ArgumentNullException(nameof(definitions));
            }
            if (!definitions.Any())
            {
                throw new ArgumentException(nameof(definitions));
            }

            var            result    = new ParserResult();
            ICommandResult command   = null;
            IOptionResult  option    = null;
            Object         arguments = null;

            var tokens = new Queue <Token>(_tokenizer.Tokenize(args, definitions));

            while (tokens.Any())
            {
                var token = tokens.Dequeue();
                switch (token.Type)
                {
                case TokenType.Argument:
                    var argument = new ArgumentResult <String>(token.Value);
                    if (command == null)
                    {
                        result.Items.Add(argument);
                    }
                    else
                    {
                        command.Argument = argument;
                    }
                    break;

                case TokenType.Command:
                    command = ParseCommand(token, definitions);
                    result.Items.Add(command);
                    break;

                case TokenType.EndListOfOptionArguments:
                    option.Argument = arguments;
                    break;

                case TokenType.StartListOfOptionArguments:
                    var innerType = option.Definition.Argument.GetType().GenericTypeArguments[0].GenericTypeArguments[0];
                    var type      = typeof(List <>).MakeGenericType(innerType);
                    arguments = Activator.CreateInstance(type);
                    break;

                case TokenType.Option:
                    option = ParseOption(token, definitions);
                    result.Items.Add(option);
                    break;

                case TokenType.OptionArgument:
                    ParseOptionArgument(token, option, (IList)arguments);
                    break;
                }
            }
            return(result);
        }