Beispiel #1
0
        public bool Resolve(IParserResult prIn, out IParserResult prOut, IBehaviors context)
        {
            IEnumerable <IRule <IParserResult> > rules =
                _rules.Union(
                    RuleDeriver.Instance.DeriveRules(prIn.CliSpecification))
                .ToList( );

            HelpOption hlpOpt = (HelpOption)prIn.CliSpecification.Options.FirstOrDefault(opt => opt is HelpOption);

            if (hlpOpt != null)
            {
                rules = rules.Select(
                    r => new HelpIsSetOr(hlpOpt, r));
            }

            RuleCheckerBase <IParserResult> rc = new RuleCheckerBase <IParserResult>(rules);

            if (rc.Check(prIn, context) == NonViolation <IParserResult> .Instance)
            {
                prOut = prIn;
                return(true);
            }

            IViolation <IParserResult> violation;

            prOut = (IParserResult)prIn.Clone( );
            while ((violation = rc.Check(prOut, context)) != NonViolation <IParserResult> .Instance)
            {
                _config.Out.WriteLine( );
                _config.Out.WriteLine(prOut);
                _config.Out.WriteLine($"> {violation.Description}");
                if (!violation.HasSolution)
                {
                    _config.Out.WriteLine("> conflict has no solution");
                    prOut = null;
                    return(false);
                }

                switch (Prompt(violation.Solutions, out ISolution <IParserResult> chosenSolution))
                {
                case UserAction.Cancel:
                    prOut = null;
                    return(false);

                case UserAction.AutoSolve:
                    AutoSolve(prOut, out prOut, rules, context);
                    break;

                case UserAction.ApplySolution:
                    ApplySolution(prOut, out prOut, chosenSolution, context);
                    break;
                }
            }

            return(true);
        }
Beispiel #2
0
 public CliSpecification(
     ICliConfig config         = null,
     IArgument dynamicArgument = null,
     params IArgument[] args) : base(true, dynamicArgument, args)
 {
     Config = config ?? commons.config.Config.New <ICliConfig>( );
     if (Config.AutoAddHelpOption)
     {
         Options.Add(HelpOption = new HelpOption(Config));
     }
 }