Example #1
0
        public ConsoleArgsState(string[] args)
        {
            ArgFinder finder = new ArgFinder();
            _findResult = finder.FindAllArgs(Assembly.GetEntryAssembly());

            ConsoleParser parser = new ConsoleParser();
            _parseResult = parser.ParseArgs(args);

            ArgAssigner assigner = new ArgAssigner();
            _assignResult = assigner.AssignValues(_findResult, _parseResult);
        }
Example #2
0
        public AssignResult AssignValues(FindResult findResult, ParseResult parseResult)
        {
            ExecutionLog errorLog = ExecutionLog.CreateErrorLog();
            HashSet<string> mandatoryFullNames = new HashSet<string>(findResult.IndexedInstances.MandatoryFullNames);

            foreach (string argName in parseResult.Arguments.Keys)
            {
                List<ArgInstance> instances = findResult.IndexedInstances.GetArgInstancesForName(argName);
                var instancesForName = findResult.IndexedInstances.GetArgInstancesForName(argName);
                if (instances.Count == 0)
                {
                    errorLog.Add("Arg named [{0}] does not exist.", argName);
                }
                else if (instances.Count > 1)
                {
                    errorLog.Add(
                        "Arg [{0}] is ambiguous. It can refer to: [{1}].",
                        argName,
                        ToStringByFullNames(instances));
                }
                else
                {
                    ArgInstance instance = instances[0];
                    SetArgInstanceValueOrAddError(instance, parseResult.Arguments[argName], errorLog);
                    mandatoryFullNames.Remove(instance.FullName);
                }
            }

            if (mandatoryFullNames.Count > 0)
            {
                List<string> sortedMandatoryArgsNotSet = new List<string>(mandatoryFullNames);
                sortedMandatoryArgsNotSet.Sort();
                errorLog.Add("Mandatory Args [{0}] were not explicitly set.",
                    string.Join(", ", sortedMandatoryArgsNotSet));
            }

            return new AssignResult(errorLog);
        }
Example #3
0
 public HelpBuilder(FindResult findResult)
 {
     _findResult = findResult;
 }