Ejemplo n.º 1
0
 private ParameterMapping(
     ParameterModel parameterModel,
     IReadOnlyList <string> suppliedValues)
 {
     SuppliedValues = suppliedValues;
     ConvertToType  = parameterModel.ParameterType;
 }
Ejemplo n.º 2
0
        public Option <(ParameterMapping, CommandLineArgumentList remainingArguments)> NamedPass(
            ParameterModel parameterModel,
            CommandLineArgumentList args)
        {
            var argumentsMatched = new List <CommandLineArgument>();
            var suppliedValues   = new List <string>();

            using (var enumerator = args.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    switch (enumerator.Current)
                    {
                    case CommandLineArgument.NameValuePair nvPair
                        when parameterModel.MatchesName(nvPair.Name):

                        argumentsMatched.Add(nvPair);

                        if (parameterModel.AllowMultipleValues)
                        {
                            suppliedValues.Add(nvPair.Value);
                            continue;
                        }

                        return(
                            new ParameterMapping.NamedValue(parameterModel, ListOf(nvPair.Value)),
                            args.Without(argumentsMatched));

                    case CommandLineArgument.BareNameOrFlag nameOrFlag
                        when parameterModel.MatchesName(nameOrFlag.Name) && parameterModel.IsFlag:
                        argumentsMatched.Add(nameOrFlag);

                        return(
                            new ParameterMapping.Flag(parameterModel),
                            args.Without(argumentsMatched));

                    case CommandLineArgument.BareNameOrFlag bnf
                        when parameterModel.MatchesName(bnf.Name):
                        if (enumerator.MoveNext())
                        {
                            if (enumerator.Current is CommandLineArgument.Free free)
                            {
                                argumentsMatched.Add(bnf);
                                argumentsMatched.Add(free);

                                if (parameterModel.AllowMultipleValues)
                                {
                                    suppliedValues.Add(free.Value);
                                    continue;
                                }

                                return(
                                    new ParameterMapping.NamedValue(
                                        parameterModel,
                                        ListOf(free.Value)),
                                    args.Without(argumentsMatched));
                            }
                        }

                        break;

                    default:
                        break;
                    }
                }
            }

            if (parameterModel.AllowMultipleValues && suppliedValues.Any())
            {
                return(
                    new ParameterMapping.NamedValue(parameterModel, suppliedValues),
                    args.Without(argumentsMatched));
            }

            return(default);
Ejemplo n.º 3
0
 public NoValue(ParameterModel parameterModel)
     : base(parameterModel, ListOf <string>())
 {
 }
Ejemplo n.º 4
0
 public Flag(ParameterModel parameterModel)
     : base(parameterModel, ListOf($"{true}"))
 {
 }
Ejemplo n.º 5
0
 public PositionalValue(
     ParameterModel parameterModel, IReadOnlyList <string> suppliedValues)
     : base(parameterModel, suppliedValues)
 {
 }