Ejemplo n.º 1
0
        private ICommand find_command(ChocolateyConfiguration config, Container container, bool isConsole, Action <ICommand> parseArgs)
        {
            if (string.IsNullOrWhiteSpace(config.CommandName))
            {
                if (isConsole)
                {
                    Environment.ExitCode = 1;
                }
                return(null);
            }

            var command = ApplicationManager.Instance.FindCommand(config.CommandName);

            if (parseArgs != null)
            {
                parseArgs.Invoke(command);
            }

            if (command.may_require_admin_access())
            {
                warn_when_admin_needs_elevation(config);
            }

            set_source_type(config);
            // guaranteed that all settings are set.
            EnvironmentSettings.set_environment_variables(config);

            this.Log().Debug(() => "Configuration: {0}".format_with(config.ToStringFull()));


            if (isConsole && (config.HelpRequested || config.UnsuccessfulParsing))
            {
                Environment.Exit(config.UnsuccessfulParsing? 1 : 0);
            }

            return(command);
        }