예제 #1
0
        private static HelpCommand GetHelpCommand(IDependencyResolverScope dependencyResolver, IParserOptions parserOptions)
        {
            var commandTypeProvider = dependencyResolver.ResolveDependency <ICommandTypeProvider>();
            var helpCommandType     = commandTypeProvider.GetCommandType(HelpCommand.Name);
            var helpCommand         = helpCommandType.CreateCommand(dependencyResolver, parserOptions) as HelpCommand;

            return(helpCommand);
        }
        /// <summary>
        /// Create the command from its type.
        /// </summary>
        /// <param name="dependencyResolver">The scoped dependendy resolver.</param>
        /// <param name="parserOptions">The options of the current parser.</param>
        /// <returns></returns>
        public ICommand CreateCommand(IDependencyResolverScope dependencyResolver, IParserOptions parserOptions)
        {
            Guard.NotNull(dependencyResolver, nameof(dependencyResolver));
            Guard.NotNull(parserOptions, nameof(parserOptions));

            var commandActivator = dependencyResolver.ResolveDependency<ICommandActivator>();
            var command = commandActivator.ActivateCommand(Type);
            var commandBase = command as CommandBase;
            commandBase?.Configure(parserOptions, dependencyResolver, this);
            return command;
        }
예제 #3
0
        /// <summary>
        /// Create the command from its type.
        /// </summary>
        /// <param name="dependencyResolver">The scoped dependendy resolver.</param>
        /// <param name="parserOptions">The options of the current parser.</param>
        /// <returns></returns>
        public ICommand CreateCommand(IDependencyResolverScope dependencyResolver, IParserOptions parserOptions)
        {
            Guard.NotNull(dependencyResolver, nameof(dependencyResolver));
            Guard.NotNull(parserOptions, nameof(parserOptions));

            var commandActivator = dependencyResolver.ResolveDependency <ICommandActivator>();
            var command          = commandActivator.ActivateCommand(Type);
            var commandBase      = command as CommandBase;

            commandBase?.Configure(parserOptions, dependencyResolver, this);
            return(command);
        }
예제 #4
0
        private static Tuple <bool, List <ValidationResult> > Validate(ICommand command, IDependencyResolverScope dependencyResolver, string commandName)
        {
            var validationContext = new ValidationContext(command, null, null);
            var results           = new List <ValidationResult>();

            var isValid = Validator.TryValidateObject(command, validationContext, results, true);

            if (!isValid)
            {
                var console = dependencyResolver.ResolveDependency <IConsole>();
                console.WriteError(Strings.Parser_CommandInvalidArgumentsFormat, commandName);
                foreach (var validation in results)
                {
                    console.WriteError(string.Format(CultureInfo.CurrentUICulture, "-{0} :", validation.ErrorMessage));
                    foreach (var memberName in validation.MemberNames)
                    {
                        console.WriteError(string.Format(CultureInfo.CurrentUICulture, "  -{0}", memberName));
                    }
                }
            }
            return(Tuple.Create(isValid, results));
        }