예제 #1
0
        /// <summary>
        ///    Run chocolatey after setting the options,
        ///    and get the count of items that would be returned if you listed the results.
        /// WARNING: Once this is called, you will not be able to register additional container components.
        /// WARNING: Ensure you don't nest additional calls to running Chocolatey here.
        /// Make a call, then finish up and make another call. This includes
        ///  - Run()
        ///  - RunConsole()
        ///  - List()
        ///  - ListCount()
        /// </summary>
        /// <remarks>
        ///    Is intended to be more efficient then simply calling <see cref="List{T}">List</see> and then Count() on the returned list.
        ///    It also returns the full count as is ignores paging.
        /// </remarks>
        public int ListCount()
        {
            ensure_environment();
            extract_resources();

            return(ensure_original_configuration(new List <string>(),
                                                 (config) =>
            {
                var runner = new GenericRunner();
                return runner.count(config, _container, isConsole: false, parseArgs: null);
            }));
        }
예제 #2
0
        /// <summary>
        ///    Run chocolatey after setting the options, and list the results.
        /// WARNING: Once this is called, you will not be able to register additional container components.
        /// </summary>
        /// <typeparam name="T">The typer of results you're expecting back.</typeparam>
        public IEnumerable <T> List <T>()
        {
            ensure_environment();
            extract_resources();

            return(ensure_original_configuration(new List <string>(),
                                                 (config) =>
            {
                config.RegularOutput = true;
                var runner = new GenericRunner();
                return runner.list <T>(config, _container, isConsole: false, parseArgs: null);
            }));
        }
예제 #3
0
        public void run(string[] args, ChocolateyConfiguration config, Container container)
        {
            this.Log().Debug(() => "Command line: {0}".format_with(Environment.CommandLine));
            this.Log().Debug(() => "Received arguments: {0}".format_with(string.Join(" ", args)));

            IList<string> commandArgs = new List<string>();
            //shift the first arg off 
            int count = 0;
            foreach (var arg in args)
            {
                if (count == 0)
                {
                    count += 1;
                    continue;
                }

                commandArgs.Add(arg);
            }

            var runner = new GenericRunner();
            runner.run(config, container, isConsole: true, parseArgs: command =>
                {
                    ConfigurationOptions.parse_arguments_and_update_configuration(
                        commandArgs,
                        config,
                        (optionSet) => command.configure_argument_parser(optionSet, config),
                        (unparsedArgs) => {
                            // if debug is bundled with local options, it may not get picked up when global 
                            // options are parsed. Attempt to set it again once local options are set.
                            // This does mean some output from debug will be missed (but not much)
                            if (config.Debug) Log4NetAppenderConfiguration.set_logging_level_debug_when_debug(config.Debug, excludeLoggerName: "{0}LoggingColoredConsoleAppender".format_with(ChocolateyLoggers.Verbose.to_string()));

                            command.handle_additional_argument_parsing(unparsedArgs, config);

                            if (!config.Features.IgnoreInvalidOptionsSwitches)
                            {
                                // all options / switches should be parsed, 
                                //  so show help menu if there are any left
                                foreach (var unparsedArg in unparsedArgs.or_empty_list_if_null())
                                {
                                    if (unparsedArg.StartsWith("-") || unparsedArg.StartsWith("/"))
                                    {
                                        config.HelpRequested = true;
                                    }
                                }
                            }
                        },
                        () => command.handle_validation(config),
                        () => command.help_message(config));
                });
        }
예제 #4
0
        /// <summary>
        /// Call this method to run Chocolatey after you have set the options.
        /// WARNING: Once this is called, you will not be able to register additional container components.
        /// WARNING: Ensure you don't nest additional calls to running Chocolatey here.
        /// Make a call, then finish up and make another call. This includes
        ///  - Run()
        ///  - RunConsole()
        ///  - List()
        ///  - ListCount()
        /// </summary>
        public void Run()
        {
            ensure_environment();
            extract_resources();

            ensure_original_configuration(new List <string>(),
                                          (config) =>
            {
                var runner = new GenericRunner();
                runner.run(config, _container, isConsole: false, parseArgs: command =>
                {
                    command.handle_validation(config);
                });
            });
        }
예제 #5
0
        private bool Execute(Action <string> outputLineCallback)
        {
            var console   = new GenericRunner();
            var container = SimpleInjectorContainer.Container;

            Config.RegularOutput = false;
            Config.Sources       = "https://chocolatey.org/api/v2/";

            var chocoCommunication = new ChocoCommunication(outputLineCallback);

            chocolatey.infrastructure.logging.Log.InitializeWith(chocoCommunication);
            console.run(Config, container, false, command => { System.Diagnostics.Debug.WriteLine($"Command {Config.CommandName} requires admin: {command.may_require_admin_access()}"); });

            return(chocoCommunication.IsSuccess);
        }
예제 #6
0
        /// <summary>
        ///   Call this method to run chocolatey after you have set the options.
        /// </summary>
        public void Run()
        {
            //refactor - thank goodness this is temporary, cuz manifest resource streams are dumb
            IList <string> folders = new List <string>
            {
                "helpers",
                "functions",
                "redirects",
                "tools"
            };

            AssemblyFileExtractor.extract_all_resources_to_relative_directory(_fileSystem, Assembly.GetAssembly(typeof(ChocolateyResourcesAssembly)), ApplicationParameters.InstallLocation, folders, ApplicationParameters.ChocolateyFileResources);
            var runner = new GenericRunner();

            runner.run(_configuration, _container, isConsole: false, parseArgs: null);
        }