コード例 #1
0
        public ParserResultConfigBackend(
            ICliSpecDeriverConfig specDeriverConfig,
            ICliSpecification spec,
            IParserResult pr,
            Type t)
        {
            if (specDeriverConfig == null)
            {
                throw new ArgumentException(
                          $"{nameof( specDeriverConfig )} must not be null",
                          nameof(specDeriverConfig));
            }
            if (spec == null)
            {
                throw new ArgumentException($"{nameof( spec )} must not be null", nameof(spec));
            }
            if (pr == null)
            {
                throw new ArgumentException($"{nameof( pr )} must not be null", nameof(pr));
            }
            if (t == null)
            {
                throw new ArgumentException($"{nameof( t )} must not be null", nameof(t));
            }

            _specDeriverConfig = specDeriverConfig;
            _spec = spec;
            _pr   = pr;
            _t    = t;
        }
コード例 #2
0
 public ConstraintsCollector(
     ICliSpecDeriverConfig specDeriverConfig,
     ICliSpecification spec)
 {
     _specDeriverConfig = specDeriverConfig;
     _spec = spec;
 }
コード例 #3
0
 public TextHelpPrinter(
     ICliSpecification spec,
     ITextHelpPrinterConfig conf = null) : base(spec)
 {
     _conf   = conf ?? Config.New <ITextHelpPrinterConfig>( );
     _writer = _conf.TextWriter;
 }
コード例 #4
0
 public InvalidOptionParser(ICliSpecification spec)
 {
     _optionPrefix = spec.Config.OptionPrefix( );
     _cmpChars     = spec.Config.CaseSensitiveOptions
        ? (Func <char, char, bool>)((c1, c2) => c1 == c2)
        : (c1, c2) => char.ToUpperInvariant(c1) == char.ToUpperInvariant(c2);
 }
コード例 #5
0
 public ParserResult(ICliSpecification cliSpecification)
 {
     CliSpecification  = cliSpecification;
     _options          = new List <IOption>( );
     _flags            = new List <IFlag>( );
     _arguments        = new Dictionary <IArgument, string>( );
     _dynamicArguments = new Dictionary <IArgument, List <string> >( );
 }
コード例 #6
0
 public ConstraintsProviderContext(ICliSpecification spec, ICliSpecDeriverConfig specDeriverConfig)
 {
     _spec = spec;
     _specDeriverConfig = specDeriverConfig;
     _itemRules         = new Dictionary <string, IRule <IParserResult> >( );
     _argumentRules     = new Dictionary <string, IRule <IParserResult> >( );
     _rules             = new List <IRule <IParserResult> >( );
 }
コード例 #7
0
 public ConflictResolver(
     ICliConfig config,
     ICliSpecification spec = null,
     Func <IList <ISolution <IParserResult> >, ISolution <IParserResult> > userPrompt = null)
 {
     _config     = config;
     _rules      = spec?.Rules ?? Enumerable.Empty <IRule <IParserResult> >( );
     _userPrompt = userPrompt ?? UserPrompt;
 }
コード例 #8
0
        public InvalidFlagParser(ICliSpecification spec)
        {
            ICliConfig conf = spec.Config;

            _flagPrefix = spec.Config.FlagPrefix( );
            _cmpChars   = conf.CaseSensitiveFlags
               ? (Func <char, char, bool>)((c1, c2) => c1 == c2)
               : (c1, c2) => char.ToUpperInvariant(c1) == char.ToUpperInvariant(c2);
        }
コード例 #9
0
ファイル: HelpPrinterBase.cs プロジェクト: jsc86/jsc.commons
        public HelpPrinterBase(ICliSpecification spec)
        {
            if (spec == null)
            {
                throw new ArgumentException($"{nameof( spec )} must not be null", nameof(spec));
            }

            Spec = spec;
        }
コード例 #10
0
        public CommandLineParser(ICliSpecification spec)
        {
            if (spec == null)
            {
                throw new NullReferenceException($"{nameof( spec )} must not be null");
            }

            new PolicyChecker(spec.Config).Check(spec);

            _spec = spec;
        }
コード例 #11
0
ファイル: FlagParser.cs プロジェクト: jsc86/jsc.commons
        public FlagParser(ICliSpecification spec)
        {
            ICliConfig conf = spec.Config;

            _flags      = spec.Flags.ToList( );
            _options    = spec.Options.Where(o => o.FlagAlias.HasValue).ToList( );
            _matches    = new List <IItem>( );
            _flagPrefix = spec.Config.FlagPrefix( );
            _cmpChars   = conf.CaseSensitiveFlags
               ? (Func <char, char, bool>)((c1, c2) => c1 == c2)
               : (c1, c2) => char.ToUpperInvariant(c1) == char.ToUpperInvariant(c2);
        }
コード例 #12
0
 private ParserResult(
     ICliSpecification cliSpecification,
     List <IOption> options,
     List <IFlag> flags,
     Dictionary <IArgument, string> arguments,
     Dictionary <IArgument, List <string> > dynamicArguments)
 {
     CliSpecification  = cliSpecification;
     _options          = options;
     _flags            = flags;
     _arguments        = arguments;
     _dynamicArguments = dynamicArguments;
 }
コード例 #13
0
        public void Check(ICliSpecification spec)
        {
            IBehaviors context = new BehaviorsBase( );

            context.Set(new ConfigBehavior(_config));
            foreach (IRule <ICliSpecification> policy in _config.Policies)
            {
                IViolation <ICliSpecification> violation = policy.Check(spec, context);
                if (violation != NonViolation <ICliSpecification> .Instance)
                {
                    throw new CliPolicyException(policy, violation);
                }
            }
        }
コード例 #14
0
        public ParserResultMapper(
            ICliSpecDeriverConfig specDeriverConfig,
            ICliSpecification spec)
        {
            if (specDeriverConfig == null)
            {
                throw new ArgumentException(
                          $"{nameof( specDeriverConfig )} must not be null",
                          nameof(specDeriverConfig));
            }
            if (spec == null)
            {
                throw new ArgumentException($"{nameof( spec )} must not be null", nameof(spec));
            }

            _specDeriverConfig = specDeriverConfig;
            _spec = spec;
        }
コード例 #15
0
        public IEnumerable <IRule <IParserResult> > DeriveRules(ICliSpecification spec)
        {
            List <IRule <IParserResult> > rules = new List <IRule <IParserResult> >( );
            List <IItem>     items = spec.Flags.Cast <IItem>( ).Union(spec.Options).ToList( );
            List <IArgument> args  = spec.Arguments.Union(items.SelectMany(i => i.Arguments)).ToList( );

            foreach (IItem item in items)
            {
                rules.AddRange(
                    _itemRuleDerivers.Where(kvp => kvp.Key.IsInstanceOfType(item))
                    .SelectMany(kvp => kvp.Value(item)));
            }

            foreach (IArgument arg in args)
            {
                rules.AddRange(
                    _argumentRuleDerivers.Where(kvp => kvp.Key.IsInstanceOfType(arg))
                    .SelectMany(kvp => kvp.Value(arg)));
            }

            return(new ReadOnlyCollection <IRule <IParserResult> >(rules));
        }