Exemplo n.º 1
0
        protected override object OnExecute(CommandContext context)
        {
            var configuration = ConfigurationCommand.GetConfiguration(context.CommandNode);

            if (configuration == null)
            {
                throw new CommandException(string.Format(Properties.Resources.Text_CannotObtainCommandTarget, "Configuration"));
            }

            if (context.Expression.Arguments.Length == 0)
            {
                throw new CommandException(Properties.Resources.Text_Command_MissingArguments);
            }

            if (context.Expression.Arguments.Length == 1)
            {
                var section = configuration.GetSection(ConfigurationUtility.GetConfigurationPath(context.Expression.Arguments[0]));
                ConfigurationCommand.Print(section, context.Output, context.Expression.Options.Contains(KEY_SIMPLIFY_OPTION), 0);
                return(section);
            }

            var sections = new Microsoft.Extensions.Configuration.IConfigurationSection[context.Expression.Arguments.Length];

            for (int i = 0; i < context.Expression.Arguments.Length; i++)
            {
                sections[i] = configuration.GetSection(ConfigurationUtility.GetConfigurationPath(context.Expression.Arguments[i]));
                ConfigurationCommand.Print(sections[i], context.Output, context.Expression.Options.Contains(KEY_SIMPLIFY_OPTION), 0);
            }

            return(sections);
        }