Ejemplo n.º 1
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) => command.handle_additional_argument_parsing(unparsedArgs, config),
                    () => command.handle_validation(config),
                    () => command.help_message(config));
            });
        }
Ejemplo n.º 2
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));
            });
        }
Ejemplo n.º 3
0
 public override void Because()
 {
     because = () => ConfigurationOptions.parse_arguments_and_update_configuration(args, config, setOptions, afterParse, validateConfiguration, helpMessage);
 }
Ejemplo n.º 4
0
        private static void set_global_options(IList <string> args, ChocolateyConfiguration config, Container container)
        {
            ConfigurationOptions.parse_arguments_and_update_configuration(
                args,
                config,
                (option_set) =>
            {
                option_set
                .Add("d|debug",
                     "Debug - Run in Debug Mode.",
                     option => config.Debug = option != null)
                .Add("v|verbose",
                     "Verbose - See verbose messaging.",
                     option => config.Verbose = option != null)
                .Add("acceptlicense|accept-license",
                     "AcceptLicense - Accept license dialogs automatically.",
                     option => config.AcceptLicense = option != null)
                .Add("y|yes|confirm",
                     "Confirm all prompts - Chooses affirmative answer instead of prompting. Implies --accept-license",
                     option =>
                {
                    config.PromptForConfirmation = option == null;
                    config.AcceptLicense         = option != null;
                })
                .Add("f|force",
                     "Force - force the behavior",
                     option => config.Force = option != null)
                .Add("noop|whatif|what-if",
                     "NoOp - Don't actually do anything.",
                     option => config.Noop = option != null)
                .Add("r|limitoutput|limit-output",
                     "LimitOutput - Limit the output to essential information",
                     option => config.RegularOutput = option == null)
                .Add("execution-timeout=",
                     "CommandExecutionTimeoutSeconds - Override the default execution timeout in the configuration of {0} seconds.".format_with(config.CommandExecutionTimeoutSeconds.to_string()),
                     option => config.CommandExecutionTimeoutSeconds = int.Parse(option.remove_surrounding_quotes()))
                .Add("c=|cache=|cachelocation=|cache-location=",
                     "CacheLocation - Location for download cache, defaults to %TEMP% or value in chocolatey.config file.",
                     option => config.CacheLocation = option.remove_surrounding_quotes())
                .Add("allowunofficial|allow-unofficial|allowunofficialbuild|allow-unofficial-build",
                     "AllowUnofficialBuild - When not using the official build you must set this flag for choco to continue.",
                     option => config.AllowUnofficialBuild = option != null)
                .Add("failstderr|failonstderr|fail-on-stderr|fail-on-standard-error|fail-on-error-output",
                     "FailOnStandardError - Fail on standard error output (stderr), typically received when running external commands during install providers. This overrides the feature failOnStandardError.",
                     option => config.Features.FailOnStandardError = option != null)
                .Add("use-system-powershell",
                     "UseSystemPowerShell - Execute PowerShell using an external process instead of the built-in PowerShell host.",
                     option => config.Features.UsePowerShellHost = option == null)
                ;
            },
                (unparsedArgs) =>
            {
                if (!string.IsNullOrWhiteSpace(config.CommandName))
                {
                    // save help for next menu
                    config.HelpRequested = false;
                }
            },
                () => { },
                () =>
            {
                var commandsLog = new StringBuilder();
                IEnumerable <ICommand> commands = container.GetAllInstances <ICommand>();
                foreach (var command in commands.or_empty_list_if_null())
                {
                    var attributes = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast <CommandForAttribute>();
                    foreach (var attribute in attributes.or_empty_list_if_null())
                    {
                        commandsLog.AppendFormat(" * {0} - {1}\n", attribute.CommandName, attribute.Description);
                    }
                }

                "chocolatey".Log().Info(@"This is a listing of all of the different things you can pass to choco.
");
                "chocolatey".Log().Info(ChocolateyLoggers.Important, "Commands");
                "chocolatey".Log().Info(@"
{0}

Please run chocolatey with `choco command -help` for specific help on
 each command.
".format_with(commandsLog.ToString()));
                "chocolatey".Log().Info(ChocolateyLoggers.Important, @"How To Pass Options / Switches");
                "chocolatey".Log().Info(@"
You can pass options and switches in the following ways:

 * Unless stated otherwise, an option/switch should only be passed one
   time. Otherwise you may find weird/non-supported behavior.
 * `-`, `/`, or `--` (one character switches should not use `--`)
 * **Option Bundling / Bundled Options**: One character switches can be
   bundled. e.g. `-d` (debug), `-f` (force), `-v` (verbose), and `-y`
   (confirm yes) can be bundled as `-dfvy`.
 * ***Note:*** If `debug` or `verbose` are bundled with local options
   (not the global ones above), some logging may not show up until after
   the local options are parsed.
 * **Use Equals**: You can also include or not include an equals sign
   `=` between options and values.
 * **Quote Values**: When you need to quote an entire argument, such as
   when using spaces, please use a combination of double quotes and
   apostrophes (`""'value'""`). In cmd.exe you can just use double quotes
   (`""value""`) but in powershell.exe you should use backticks
   (`` `""value`"" ``) or apostrophes (`'value'`). Using the combination
   allows for both shells to work without issue, except for when the next
   section applies.
 * **Pass quotes in arguments**: When you need to pass quoted values to
   to something like a native installer, you are in for a world of fun. In
   cmd.exe you must pass it like this: `-ia ""/yo=""""Spaces spaces""""""`. In
   PowerShell.exe, you must pass it like this: `-ia '/yo=""""Spaces spaces""""'`.
   No other combination will work. In PowerShell.exe if you are on version
   v3+, you can try `--%` before `-ia` to just pass the args through as is,
   which means it should not require any special workarounds.
 * Options and switches apply to all items passed, so if you are
   installing multiple packages, and you use `--version=1.0.0`, choco
   is going to look for and try to install version 1.0.0 of every
   package passed. So please split out multiple package calls when
   wanting to pass specific options.
");
                "chocolatey".Log().Info(ChocolateyLoggers.Important, "Default Options and Switches");
            });
        }
Ejemplo n.º 5
0
        private static void set_global_options(IList <string> args, ChocolateyConfiguration config, Container container)
        {
            ConfigurationOptions.parse_arguments_and_update_configuration(
                args,
                config,
                (option_set) =>
            {
                option_set
                .Add("d|debug",
                     "Debug - Show debug messaging.",
                     option => config.Debug = option != null)
                .Add("v|verbose",
                     "Verbose - Show verbose messaging. Very verbose messaging, avoid using under normal circumstances.",
                     option => config.Verbose = option != null)
                .Add("trace",
                     "Trace - Show trace messaging. Very, very verbose trace messaging. Avoid except when needing super low-level .NET Framework debugging. Available in 0.10.4+.",
                     option => config.Trace = option != null)
                .Add("acceptlicense|accept-license",
                     "AcceptLicense - Accept license dialogs automatically. Reserved for future use.",
                     option => config.AcceptLicense = option != null)
                .Add("y|yes|confirm",
                     "Confirm all prompts - Chooses affirmative answer instead of prompting. Implies --accept-license",
                     option =>
                {
                    config.PromptForConfirmation = option == null;
                    config.AcceptLicense         = option != null;
                })
                .Add("f|force",
                     "Force - force the behavior. Do not use force during normal operation - it subverts some of the smart behavior for commands.",
                     option => config.Force = option != null)
                .Add("noop|whatif|what-if",
                     "NoOp / WhatIf - Don't actually do anything.",
                     option => config.Noop = option != null)
                .Add("r|limitoutput|limit-output",
                     "LimitOutput - Limit the output to essential information",
                     option => config.RegularOutput = option == null)
                .Add("timeout=|execution-timeout=",
                     "CommandExecutionTimeout (in seconds) - The time to allow a command to finish before timing out. Overrides the default execution timeout in the configuration of {0} seconds. '0' for infinite starting in 0.10.4.".format_with(config.CommandExecutionTimeoutSeconds.to_string()),
                     option =>
                {
                    int timeout = 0;
                    int.TryParse(option.remove_surrounding_quotes(), out timeout);
                    if (timeout > 0)
                    {
                        config.CommandExecutionTimeoutSeconds = timeout;
                    }
                })
                .Add("c=|cache=|cachelocation=|cache-location=",
                     "CacheLocation - Location for download cache, defaults to %TEMP% or value in chocolatey.config file.",
                     option => config.CacheLocation = option.remove_surrounding_quotes())
                .Add("allowunofficial|allow-unofficial|allowunofficialbuild|allow-unofficial-build",
                     "AllowUnofficialBuild - When not using the official build you must set this flag for choco to continue.",
                     option => config.AllowUnofficialBuild = option != null)
                .Add("failstderr|failonstderr|fail-on-stderr|fail-on-standard-error|fail-on-error-output",
                     "FailOnStandardError - Fail on standard error output (stderr), typically received when running external commands during install providers. This overrides the feature failOnStandardError.",
                     option => config.Features.FailOnStandardError = option != null)
                .Add("use-system-powershell",
                     "UseSystemPowerShell - Execute PowerShell using an external process instead of the built-in PowerShell host. Should only be used when internal host is failing. Available in 0.9.10+.",
                     option => config.Features.UsePowerShellHost = option == null)
                .Add("no-progress",
                     "Do Not Show Progress - Do not show download progress percentages. Available in 0.10.4+.",
                     option => config.Features.ShowDownloadProgress = option == null)
                .Add("proxy=",
                     "Proxy Location - Explicit proxy location. Overrides the default proxy location of '{0}'. Available for config settings in 0.9.9.9+, this CLI option available in 0.10.4+.".format_with(config.Proxy.Location),
                     option => config.Proxy.Location = option.remove_surrounding_quotes())
                .Add("proxy-user="******"Proxy User Name - Explicit proxy user (optional). Requires explicity proxy (`--proxy` or config setting). Overrides the default proxy user of '{0}'. Available for config settings in 0.9.9.9+, this CLI option available in 0.10.4+.".format_with(config.Proxy.User),
                     option => config.Proxy.User = option.remove_surrounding_quotes())
                .Add("proxy-password="******"Proxy Password - Explicit proxy password (optional) to be used with username. Requires explicity proxy (`--proxy` or config setting) and user name.  Overrides the default proxy password (encrypted in settings if set). Available for config settings in 0.9.9.9+, this CLI option available in 0.10.4+.",
                     option => config.Proxy.EncryptedPassword = NugetEncryptionUtility.EncryptString(option.remove_surrounding_quotes()))
                .Add("proxy-bypass-list=",
                     "ProxyBypassList - Comma separated list of regex locations to bypass on proxy. Requires explicity proxy (`--proxy` or config setting). Overrides the default proxy bypass list of '{0}'. Available in 0.10.4+.".format_with(config.Proxy.BypassList),
                     option => config.Proxy.BypassList = option.remove_surrounding_quotes())
                .Add("proxy-bypass-on-local",
                     "Proxy Bypass On Local - Bypass proxy for local connections. Requires explicity proxy (`--proxy` or config setting). Overrides the default proxy bypass on local setting of '{0}'. Available in 0.10.4+.".format_with(config.Proxy.BypassOnLocal),
                     option => config.Proxy.BypassOnLocal = option != null)
                ;
            },
                (unparsedArgs) =>
            {
                if (!string.IsNullOrWhiteSpace(config.CommandName))
                {
                    // save help for next menu
                    config.HelpRequested       = false;
                    config.UnsuccessfulParsing = false;
                }
            },
                () => { },
                () =>
            {
                var commandsLog = new StringBuilder();
                IEnumerable <ICommand> commands = container.GetAllInstances <ICommand>();
                foreach (var command in commands.or_empty_list_if_null())
                {
                    var attributes = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast <CommandForAttribute>();
                    foreach (var attribute in attributes.or_empty_list_if_null())
                    {
                        commandsLog.AppendFormat(" * {0} - {1}\n", attribute.CommandName, attribute.Description);
                    }
                }

                "chocolatey".Log().Info(@"This is a listing of all of the different things you can pass to choco.
");
                "chocolatey".Log().Info(ChocolateyLoggers.Important, "Commands");
                "chocolatey".Log().Info(@"
{0}

Please run chocolatey with `choco command -help` for specific help on
 each command.
".format_with(commandsLog.ToString()));
                "chocolatey".Log().Info(ChocolateyLoggers.Important, @"How To Pass Options / Switches");
                "chocolatey".Log().Info(@"
You can pass options and switches in the following ways:

 * Unless stated otherwise, an option/switch should only be passed one
   time. Otherwise you may find weird/non-supported behavior.
 * `-`, `/`, or `--` (one character switches should not use `--`)
 * **Option Bundling / Bundled Options**: One character switches can be
   bundled. e.g. `-d` (debug), `-f` (force), `-v` (verbose), and `-y`
   (confirm yes) can be bundled as `-dfvy`.
 * NOTE: If `debug` or `verbose` are bundled with local options
   (not the global ones above), some logging may not show up until after
   the local options are parsed.
 * **Use Equals**: You can also include or not include an equals sign
   `=` between options and values.
 * **Quote Values**: When you need to quote an entire argument, such as
   when using spaces, please use a combination of double quotes and
   apostrophes (`""'value'""`). In cmd.exe you can just use double quotes
   (`""value""`) but in powershell.exe you should use backticks
   (`` `""value`"" ``) or apostrophes (`'value'`). Using the combination
   allows for both shells to work without issue, except for when the next
   section applies.
 * **Periods in PowerShell**: If you need to pass a period as part of a 
   value or a path, PowerShell doesn't always handle it well. Please 
   quote those values using ""Quote Values"" section above.
 * **Pass quotes in arguments**: When you need to pass quoted values to
   to something like a native installer, you are in for a world of fun. In
   cmd.exe you must pass it like this: `-ia ""/yo=""""Spaces spaces""""""`. In
   PowerShell.exe, you must pass it like this: `-ia '/yo=""""Spaces spaces""""'`.
   No other combination will work. In PowerShell.exe if you are on version
   v3+, you can try `--%` before `-ia` to just pass the args through as is,
   which means it should not require any special workarounds.
 * Options and switches apply to all items passed, so if you are
   installing multiple packages, and you use `--version=1.0.0`, choco
   is going to look for and try to install version 1.0.0 of every
   package passed. So please split out multiple package calls when
   wanting to pass specific options.
");
                "chocolatey".Log().Info(ChocolateyLoggers.Important, "Default Options and Switches");
            });
        }
Ejemplo n.º 6
0
 private static void set_global_options(IList <string> args, ChocolateyConfiguration config, Container container)
 {
     ConfigurationOptions.parse_arguments_and_update_configuration(
         args,
         config,
         (option_set) =>
     {
         option_set
         .Add("d|debug",
              "Debug - Show debug messaging.",
              option => config.Debug = option != null)
         .Add("v|verbose",
              "Verbose - Show verbose messaging. Very verbose messaging, avoid using under normal circumstances.",
              option => config.Verbose = option != null)
         .Add("trace",
              "Trace - Show trace messaging. Very, very verbose trace messaging. Avoid except when needing super low-level .NET Framework debugging. Available in 0.10.4+.",
              option => config.Trace = option != null)
         .Add("nocolor|no-color",
              "No Color - Do not show colorization in logging output. This overrides the feature '{0}', set to '{1}'. Available in 0.10.9+.".format_with(ApplicationParameters.Features.LogWithoutColor, config.Features.LogWithoutColor),
              option => config.Features.LogWithoutColor = option != null)
         .Add("acceptlicense|accept-license",
              "AcceptLicense - Accept license dialogs automatically. Reserved for future use.",
              option => config.AcceptLicense = option != null)
         .Add("y|yes|confirm",
              "Confirm all prompts - Chooses affirmative answer instead of prompting. Implies --accept-license",
              option =>
         {
             config.PromptForConfirmation = option == null;
             config.AcceptLicense         = option != null;
         })
         .Add("f|force",
              "Force - force the behavior. Do not use force during normal operation - it subverts some of the smart behavior for commands.",
              option => config.Force = option != null)
         .Add("noop|whatif|what-if",
              "NoOp / WhatIf - Don't actually do anything.",
              option => config.Noop = option != null)
         .Add("r|limitoutput|limit-output",
              "LimitOutput - Limit the output to essential information",
              option => config.RegularOutput = option == null)
         .Add("timeout=|execution-timeout=",
              "CommandExecutionTimeout (in seconds) - The time to allow a command to finish before timing out. Overrides the default execution timeout in the configuration of {0} seconds. '0' for infinite starting in 0.10.4.".format_with(config.CommandExecutionTimeoutSeconds.to_string()),
              option =>
         {
             int timeout       = 0;
             var timeoutString = option.remove_surrounding_quotes();
             int.TryParse(timeoutString, out timeout);
             if (timeout > 0 || timeoutString.is_equal_to("0"))
             {
                 config.CommandExecutionTimeoutSeconds = timeout;
             }
         })
         .Add("c=|cache=|cachelocation=|cache-location=",
              "CacheLocation - Location for download cache, defaults to %TEMP% or value in chocolatey.config file.",
              option => config.CacheLocation = option.remove_surrounding_quotes())
         .Add("allowunofficial|allow-unofficial|allowunofficialbuild|allow-unofficial-build",
              "AllowUnofficialBuild - When not using the official build you must set this flag for choco to continue.",
              option => config.AllowUnofficialBuild = option != null)
         .Add("failstderr|failonstderr|fail-on-stderr|fail-on-standard-error|fail-on-error-output",
              "FailOnStandardError - Fail on standard error output (stderr), typically received when running external commands during install providers. This overrides the feature failOnStandardError.",
              option => config.Features.FailOnStandardError = option != null)
         .Add("use-system-powershell",
              "UseSystemPowerShell - Execute PowerShell using an external process instead of the built-in PowerShell host. Should only be used when internal host is failing. Available in 0.9.10+.",
              option => config.Features.UsePowerShellHost = option == null)
         .Add("no-progress",
              "Do Not Show Progress - Do not show download progress percentages. Available in 0.10.4+.",
              option => config.Features.ShowDownloadProgress = option == null)
         .Add("proxy=",
              "Proxy Location - Explicit proxy location. Overrides the default proxy location of '{0}'. Available for config settings in 0.9.9.9+, this CLI option available in 0.10.4+.".format_with(config.Proxy.Location),
              option => config.Proxy.Location = option.remove_surrounding_quotes())
         .Add("proxy-user="******"Proxy User Name - Explicit proxy user (optional). Requires explicit proxy (`--proxy` or config setting). Overrides the default proxy user of '{0}'. Available for config settings in 0.9.9.9+, this CLI option available in 0.10.4+.".format_with(config.Proxy.User),
              option => config.Proxy.User = option.remove_surrounding_quotes())
         .Add("proxy-password="******"Proxy Password - Explicit proxy password (optional) to be used with username. Requires explicit proxy (`--proxy` or config setting) and user name.  Overrides the default proxy password (encrypted in settings if set). Available for config settings in 0.9.9.9+, this CLI option available in 0.10.4+.",
              option => config.Proxy.EncryptedPassword = NugetEncryptionUtility.EncryptString(option.remove_surrounding_quotes()))
         .Add("proxy-bypass-list=",
              "ProxyBypassList - Comma separated list of regex locations to bypass on proxy. Requires explicit proxy (`--proxy` or config setting). Overrides the default proxy bypass list of '{0}'. Available in 0.10.4+.".format_with(config.Proxy.BypassList),
              option => config.Proxy.BypassList = option.remove_surrounding_quotes())
         .Add("proxy-bypass-on-local",
              "Proxy Bypass On Local - Bypass proxy for local connections. Requires explicit proxy (`--proxy` or config setting). Overrides the default proxy bypass on local setting of '{0}'. Available in 0.10.4+.".format_with(config.Proxy.BypassOnLocal),
              option => config.Proxy.BypassOnLocal = option != null)
         .Add("log-file=",
              "Log File to output to in addition to regular loggers. Available in 0.10.8+.",
              option => config.AdditionalLogFileLocation = option.remove_surrounding_quotes())
         ;
     },
         (unparsedArgs) =>
     {
         if (!string.IsNullOrWhiteSpace(config.CommandName))
         {
             // save help for next menu
             config.HelpRequested       = false;
             config.UnsuccessfulParsing = false;
         }
     },
         () => { },
         () =>
     {
         ChocolateyHelpCommand.display_help_message(container);
     });
 }
Ejemplo n.º 7
0
        private static void set_global_options(IList <string> args, ChocolateyConfiguration config)
        {
            ConfigurationOptions.parse_arguments_and_update_configuration(
                args,
                config,
                (option_set) =>
            {
                option_set
                .Add("d|debug",
                     "Debug - Run in Debug Mode.",
                     option => config.Debug = option != null)
                .Add("v|verbose",
                     "Verbose - See verbose messaging.",
                     option => config.Verbose = option != null)
                .Add("acceptlicense|accept-license",
                     "AcceptLicense - Accept license dialogs automatically.",
                     option => config.AcceptLicense = option != null)
                .Add("y|yes|confirm",
                     "Confirm all prompts - Chooses affirmative answer instead of prompting. Implies --accept-license",
                     option =>
                {
                    config.PromptForConfirmation = option == null;
                    config.AcceptLicense         = option != null;
                })
                .Add("f|force",
                     "Force - force the behavior",
                     option => config.Force = option != null)
                .Add("noop|whatif|what-if",
                     "NoOp - Don't actually do anything.",
                     option => config.Noop = option != null)
                .Add("r|limitoutput|limit-output",
                     "LimitOutput - Limit the output to essential information",
                     option => config.RegularOutput = option == null)
                .Add("execution-timeout=",
                     "CommandExecutionTimeoutSeconds - Override the default execution timeout in the configuration of {0} seconds.".format_with(config.CommandExecutionTimeoutSeconds.to_string()),
                     option => config.CommandExecutionTimeoutSeconds = int.Parse(option.remove_surrounding_quotes()))
                .Add("c=|cache=|cachelocation=|cache-location=",
                     "CacheLocation - Location for download cache, defaults to %TEMP% or value in chocolatey.config file.",
                     option => config.CacheLocation = option.remove_surrounding_quotes())
                .Add("allowunofficial|allow-unofficial|allowunofficialbuild|allow-unofficial-build",
                     "AllowUnofficialBuild - When not using the official build you must set this flag for choco to continue.",
                     option => config.AllowUnofficialBuild = option != null)
                ;
            },
                (unparsedArgs) =>
            {
                if (!string.IsNullOrWhiteSpace(config.CommandName))
                {
                    // save help for next menu
                    config.HelpRequested = false;
                }
            },
                () => { },
                () =>
            {
                var commandsLog = new StringBuilder();
                foreach (var command in Enum.GetValues(typeof(CommandNameType)).Cast <CommandNameType>())
                {
                    commandsLog.AppendFormat(" * {0}\n", command.get_description_or_value());
                }

                "chocolatey".Log().Info(@"This is a listing of all of the different things you can pass to choco.
");
                "chocolatey".Log().Info(ChocolateyLoggers.Important, "Commands");
                "chocolatey".Log().Info(@"
{0}

Please run chocolatey with `choco command -help` for specific help on
 each command.
".format_with(commandsLog.ToString()));
                "chocolatey".Log().Info(ChocolateyLoggers.Important, @"How To Pass Options / Switches");
                "chocolatey".Log().Info(@"
You can pass options and switches in the following ways:

 * `-`, `/`, or `--` (one character switches should not use `--`)
 * **Option Bundling / Bundled Options**: One character switches can be
   bundled. e.g. `-d` (debug), `-f` (force), `-v` (verbose), and `-y`
   (confirm yes) can be bundled as `-dfvy`.
 * ***Note:*** If `debug` or `verbose` are bundled with local options
   (not the global ones above), some logging may not show up until after
   the local options are parsed.
 * **Use Equals**: You can also include or not include an equals sign
   `=` between options and values.
 * **Quote Values**: When you need to quote things, such as when using
   spaces, please use apostrophes (`'value'`). In cmd.exe you may be
   able to use just double quotes (`""value""`) but in powershell.exe
   you may need to either escape the quotes with backticks
   (`` `""value`"" ``) or use a combination of double quotes and
   apostrophes (`""'value'""`). This is due to the hand off to
   PowerShell - it seems to strip off the outer set of quotes.
 * Options and switches apply to all items passed, so if you are
   installing multiple packages, and you use `--version=1.0.0`, choco
   is going to look for and try to install version 1.0.0 of every
   package passed. So please split out multiple package calls when
   wanting to pass specific options.
");
                "chocolatey".Log().Info(ChocolateyLoggers.Important, "Default Options and Switches");
            });
        }
Ejemplo n.º 8
0
        private static void set_global_options(IList <string> args, ChocolateyConfiguration config)
        {
            ConfigurationOptions.parse_arguments_and_update_configuration(
                args,
                config,
                (option_set) =>
            {
                option_set
                .Add("d|debug",
                     "Debug - Run in Debug Mode.",
                     option => config.Debug = option != null)
                .Add("v|verbose",
                     "Verbose - See verbose messaging.",
                     option => config.Verbose = option != null)
                .Add("acceptlicense|accept-license",
                     "AcceptLicense - Accept license dialogs automatically.",
                     option => config.AcceptLicense = option != null)
                .Add("y|yes|confirm",
                     "Confirm all prompts - Chooses default answer instead of prompting. Implies --accept-license",
                     option =>
                {
                    config.PromptForConfirmation = option == null;
                    config.AcceptLicense         = option != null;
                })
                .Add("f|force",
                     "Force - force the behavior",
                     option => config.Force = option != null)
                .Add("noop|whatif|what-if",
                     "NoOp - Don't actually do anything.",
                     option => config.Noop = option != null)
                .Add("r|limitoutput|limit-output",
                     "LimitOuptut - Limit the output to essential information",
                     option => config.RegularOuptut = option == null)
                .Add("execution-timeout=",
                     "CommandExecutionTimeoutSeconds - Override the default execution timeout in the configuration of {0} seconds.".format_with(config.CommandExecutionTimeoutSeconds.to_string()),
                     option => config.CommandExecutionTimeoutSeconds = int.Parse(option))
                .Add("c=|cache=|cachelocation=|cache-location=",
                     "CacheLocation - Location for download cache, defaults to %TEMP% or value in chocolatey.config file.",
                     option => config.CacheLocation = option)
                .Add("allowunofficial|allow-unofficial|allowunofficialbuild|allow-unofficial-build",
                     "AllowUnofficialBuild - When not using the official build you must set this flag for choco to continue.",
                     option => config.AllowUnofficialBuild = option != null)
                ;
            },
                (unparsedArgs) =>
            {
                if (!string.IsNullOrWhiteSpace(config.CommandName))
                {
                    // save help for next menu
                    config.HelpRequested = false;
                }
            },
                () => { },
                () =>
            {
                var commandsLog = new StringBuilder();
                foreach (var command in Enum.GetValues(typeof(CommandNameType)).Cast <CommandNameType>())
                {
                    commandsLog.AppendFormat(" * {0}\n", command.get_description_or_value());
                }

                "chocolatey".Log().Info(ChocolateyLoggers.Important, "Commands");
                "chocolatey".Log().Info(@"{1}

Please run chocolatey with `choco command -help` for specific help on each command.".format_with(config.Information.ChocolateyVersion, commandsLog.ToString()));
            });
        }
Ejemplo n.º 9
0
        public void run(string[] args, ChocolateyConfiguration config, Container container)
        {
            var commandLine = Environment.CommandLine;

            if (ArgumentsUtility.arguments_contain_sensitive_information(commandLine))
            {
                this.Log().Debug(() => "Command line not shown - sensitive arguments may have been passed.");
            }
            else
            {
                this.Log().Debug(() => "Command line: {0}".format_with(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, "{0}LoggingColoredConsoleAppender".format_with(ChocolateyLoggers.Verbose.to_string()), "{0}LoggingColoredConsoleAppender".format_with(ChocolateyLoggers.Trace.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;
                                config.UnsuccessfulParsing = true;
                            }
                        }
                    }
                },
                    () => {
                    this.Log().Debug(() => "Performing validation checks.");
                    command.handle_validation(config);

                    var validationResults = new List <ValidationResult>();
                    var validationChecks  = container.GetAllInstances <IValidation>();
                    foreach (var validationCheck in validationChecks)
                    {
                        validationResults.AddRange(validationCheck.validate(config));
                    }

                    var validationErrors = report_validation_summary(validationResults, config);

                    if (validationErrors != 0)
                    {
                        // NOTE: This is intentionally left blank, as the reason for throwing is
                        // documented in the report_validation_summary above, and a duplication
                        // is not required in the exception.
                        throw new ApplicationException("");
                    }
                },
                    () => command.help_message(config));
            });
        }
Ejemplo n.º 10
0
        private static void set_global_options(IList <string> args, ChocolateyConfiguration config)
        {
            ConfigurationOptions.parse_arguments_and_update_configuration(
                args,
                config,
                (option_set) =>
            {
                option_set
                .Add("d|debug",
                     "Debug - Run in Debug Mode.",
                     option => config.Debug = option != null)
                .Add("v|verbose",
                     "Verbose - See verbose messaging.",
                     option => config.Verbose = option != null)
                .Add("acceptlicense|accept-license",
                     "AcceptLicense - Accept license dialogs automatically.",
                     option => config.AcceptLicense = option != null)
                .Add("y|yes|confirm",
                     "Confirm all prompts - Chooses default answer instead of prompting. Implies --accept-license",
                     option =>
                {
                    config.PromptForConfirmation = option == null;
                    config.AcceptLicense         = option != null;
                })
                .Add("f|force",
                     "Force - force the behavior",
                     option => config.Force = option != null)
                .Add("noop|whatif|what-if",
                     "NoOp - Don't actually do anything.",
                     option => config.Noop = option != null)
                .Add("r|limitoutput|limit-output",
                     "LimitOuptut - Limit the output to essential information",
                     option => config.RegularOuptut = option == null)
                .Add("execution-timeout=",
                     "CommandExecutionTimeoutSeconds - Override the default execution timeout in the configuration of {0} seconds.".format_with(config.CommandExecutionTimeoutSeconds.to_string()),
                     option => config.CommandExecutionTimeoutSeconds = int.Parse(option))
                .Add("c=|cache=|cachelocation=|cache-location=",
                     "CacheLocation - Location for download cache, defaults to %TEMP% or value in chocolatey.config file.",
                     option => config.CacheLocation = option)
                .Add("allowunofficial|allow-unofficial|allowunofficialbuild|allow-unofficial-build",
                     "AllowUnofficialBuild - When not using the official build you must set this flag for choco to continue.",
                     option => config.AllowUnofficialBuild = option != null)
                ;
            },
                (unparsedArgs) =>
            {
                if (!string.IsNullOrWhiteSpace(config.CommandName))
                {
                    // save help for next menu
                    config.HelpRequested = false;
                }
            },
                () => { },
                () =>
            {
                var commandsLog = new StringBuilder();
                foreach (var command in Enum.GetValues(typeof(CommandNameType)).Cast <CommandNameType>())
                {
                    commandsLog.AppendFormat(" * {0}\n", command.get_description_or_value());
                }

                "chocolatey".Log().Info(@"This is a listing of all of the different things you can pass to choco.
");
                "chocolatey".Log().Info(ChocolateyLoggers.Important, "Commands");
                "chocolatey".Log().Info(@"
{1}

Please run chocolatey with `choco command -help` for specific help on 
 each command.
".format_with(config.Information.ChocolateyVersion, commandsLog.ToString()));
                "chocolatey".Log().Info(ChocolateyLoggers.Important, @"How To Pass Options / Switches");
                "chocolatey".Log().Info(@"
You can pass options and switches in the following ways:

 * `-` - except for normal switches (not 1 character) when using option
   blending, see below.
 * `--` - except for one character switches
 * `/`
 * ""Option Blending / Blended Options"": One character switches can be 
   blended. e.g. `-d` (debug), `-f` (force), `-v` (verbose), and `-y` 
   (confirm yes) can be blended as `-dfvy`, but you must use `--` for 
   all other normal options/switches e.g. `--version` instead of 
   `-version`. If you don't do this, you may have unintended results.
 * ""Use Equals"": You can also include or not include an equals sign 
   `=` between options and values. And quote the values.
 * Options and switches apply to all items passed, so if you are 
   installing multiple packages, and you use `--version=1.0.0`, it is 
   going to look for and try to install version 1.0.0 of every package 
   passed. So please split out multiple package calls when wanting to 
   pass specific options.
 * When you need to quote things, such as when using spaces in option 
   values, please use single quote marks ('). In cmd.exe, you can also 
   use double double quotes (i.e. """"yo""""). This is due to the hand 
   off to PowerShell - seems to strip off the outer set of quotes. 
   TODO: TEST THIS, MAY NOT BE RELEVANT NOW.
");
                "chocolatey".Log().Info(ChocolateyLoggers.Important, "Default Options and Switches");
            });
        }
Ejemplo n.º 11
0
        private static void set_global_options(IList <string> args, ChocolateyConfiguration config, Container container)
        {
            ConfigurationOptions.parse_arguments_and_update_configuration(
                args,
                config,
                (option_set) =>
            {
                option_set
                .Add("d|debug",
                     "Debug - Show debug messaging.",
                     option => config.Debug = option != null)
                .Add("v|verbose",
                     "Verbose - Show verbose messaging. Very verbose messaging, avoid using under normal circumstances.",
                     option => config.Verbose = option != null)
                .Add("trace",
                     "Trace - Show trace messaging. Very, very verbose trace messaging. Avoid except when needing super low-level .NET Framework debugging. Available in 0.10.4+.",
                     option => config.Trace = option != null)
                .Add("nocolor|no-color",
                     "No Color - Do not show colorization in logging output. This overrides the feature '{0}', set to '{1}'. Available in 0.10.9+.".format_with(ApplicationParameters.Features.LogWithoutColor, config.Features.LogWithoutColor),
                     option => config.Features.LogWithoutColor = option != null)
                .Add("acceptlicense|accept-license",
                     "AcceptLicense - Accept license dialogs automatically. Reserved for future use.",
                     option => config.AcceptLicense = option != null)
                .Add("y|yes|confirm",
                     "Confirm all prompts - Chooses affirmative answer instead of prompting. Implies --accept-license",
                     option =>
                {
                    config.PromptForConfirmation = option == null;
                    config.AcceptLicense         = option != null;
                })
                .Add("f|force",
                     "Force - force the behavior. Do not use force during normal operation - it subverts some of the smart behavior for commands.",
                     option => config.Force = option != null)
                .Add("noop|whatif|what-if",
                     "NoOp / WhatIf - Don't actually do anything.",
                     option => config.Noop = option != null)
                .Add("r|limitoutput|limit-output",
                     "LimitOutput - Limit the output to essential information",
                     option => config.RegularOutput = option == null)
                .Add("timeout=|execution-timeout=",
                     "CommandExecutionTimeout (in seconds) - The time to allow a command to finish before timing out. Overrides the default execution timeout in the configuration of {0} seconds. '0' for infinite starting in 0.10.4.".format_with(config.CommandExecutionTimeoutSeconds.to_string()),
                     option =>
                {
                    int timeout       = 0;
                    var timeoutString = option.remove_surrounding_quotes();
                    int.TryParse(timeoutString, out timeout);
                    if (timeout > 0 || timeoutString.is_equal_to("0"))
                    {
                        config.CommandExecutionTimeoutSeconds = timeout;
                    }
                })
                .Add("c=|cache=|cachelocation=|cache-location=",
                     "CacheLocation - Location for download cache, defaults to %TEMP% or value in chocolatey.config file.",
                     option => config.CacheLocation = option.remove_surrounding_quotes())
                .Add("allowunofficial|allow-unofficial|allowunofficialbuild|allow-unofficial-build",
                     "AllowUnofficialBuild - When not using the official build you must set this flag for choco to continue.",
                     option => config.AllowUnofficialBuild = option != null)
                .Add("failstderr|failonstderr|fail-on-stderr|fail-on-standard-error|fail-on-error-output",
                     "FailOnStandardError - Fail on standard error output (stderr), typically received when running external commands during install providers. This overrides the feature failOnStandardError.",
                     option => config.Features.FailOnStandardError = option != null)
                .Add("use-system-powershell",
                     "UseSystemPowerShell - Execute PowerShell using an external process instead of the built-in PowerShell host. Should only be used when internal host is failing. Available in 0.9.10+.",
                     option => config.Features.UsePowerShellHost = option == null)
                .Add("no-progress",
                     "Do Not Show Progress - Do not show download progress percentages. Available in 0.10.4+.",
                     option => config.Features.ShowDownloadProgress = option == null)
                .Add("proxy=",
                     "Proxy Location - Explicit proxy location. Overrides the default proxy location of '{0}'. Available for config settings in 0.9.9.9+, this CLI option available in 0.10.4+.".format_with(config.Proxy.Location),
                     option => config.Proxy.Location = option.remove_surrounding_quotes())
                .Add("proxy-user="******"Proxy User Name - Explicit proxy user (optional). Requires explicity proxy (`--proxy` or config setting). Overrides the default proxy user of '{0}'. Available for config settings in 0.9.9.9+, this CLI option available in 0.10.4+.".format_with(config.Proxy.User),
                     option => config.Proxy.User = option.remove_surrounding_quotes())
                .Add("proxy-password="******"Proxy Password - Explicit proxy password (optional) to be used with username. Requires explicity proxy (`--proxy` or config setting) and user name.  Overrides the default proxy password (encrypted in settings if set). Available for config settings in 0.9.9.9+, this CLI option available in 0.10.4+.",
                     option => config.Proxy.EncryptedPassword = NugetEncryptionUtility.EncryptString(option.remove_surrounding_quotes()))
                .Add("proxy-bypass-list=",
                     "ProxyBypassList - Comma separated list of regex locations to bypass on proxy. Requires explicity proxy (`--proxy` or config setting). Overrides the default proxy bypass list of '{0}'. Available in 0.10.4+.".format_with(config.Proxy.BypassList),
                     option => config.Proxy.BypassList = option.remove_surrounding_quotes())
                .Add("proxy-bypass-on-local",
                     "Proxy Bypass On Local - Bypass proxy for local connections. Requires explicity proxy (`--proxy` or config setting). Overrides the default proxy bypass on local setting of '{0}'. Available in 0.10.4+.".format_with(config.Proxy.BypassOnLocal),
                     option => config.Proxy.BypassOnLocal = option != null)
                .Add("log-file=",
                     "Log File to output to in addition to regular loggers. Available in 0.10.8+.",
                     option => config.AdditionalLogFileLocation = option.remove_surrounding_quotes())
                ;
            },
                (unparsedArgs) =>
            {
                if (!string.IsNullOrWhiteSpace(config.CommandName))
                {
                    // save help for next menu
                    config.HelpRequested       = false;
                    config.UnsuccessfulParsing = false;
                }
            },
                () => { },
                () =>
            {
                var commandsLog = new StringBuilder();
                IEnumerable <ICommand> commands = container.GetAllInstances <ICommand>();
                foreach (var command in commands.or_empty_list_if_null())
                {
                    var attributes = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast <CommandForAttribute>();
                    foreach (var attribute in attributes.or_empty_list_if_null())
                    {
                        commandsLog.AppendFormat(" * {0} - {1}\n", attribute.CommandName, attribute.Description);
                    }
                }

                "chocolatey".Log().Info(@"This is a listing of all of the different things you can pass to choco.
");
                "chocolatey".Log().Info(ChocolateyLoggers.Important, "Commands");
                "chocolatey".Log().Info(@"
{0}

Please run chocolatey with `choco command -help` for specific help on
 each command.
".format_with(commandsLog.ToString()));
                "chocolatey".Log().Info(ChocolateyLoggers.Important, @"How To Pass Options / Switches");
                "chocolatey".Log().Info(@"
You can pass options and switches in the following ways:

 * Unless stated otherwise, an option/switch should only be passed one
   time. Otherwise you may find weird/non-supported behavior.
 * `-`, `/`, or `--` (one character switches should not use `--`)
 * **Option Bundling / Bundled Options**: One character switches can be
   bundled. e.g. `-d` (debug), `-f` (force), `-v` (verbose), and `-y`
   (confirm yes) can be bundled as `-dfvy`.
 * NOTE: If `debug` or `verbose` are bundled with local options
   (not the global ones above), some logging may not show up until after
   the local options are parsed.
 * **Use Equals**: You can also include or not include an equals sign
   `=` between options and values.
 * **Quote Values**: When you need to quote an entire argument, such as
   when using spaces, please use a combination of double quotes and
   apostrophes (`""'value'""`). In cmd.exe you can just use double quotes
   (`""value""`) but in powershell.exe you should use backticks
   (`` `""value`"" ``) or apostrophes (`'value'`). Using the combination
   allows for both shells to work without issue, except for when the next
   section applies.
 * **Pass quotes in arguments**: When you need to pass quoted values to
   to something like a native installer, you are in for a world of fun. In
   cmd.exe you must pass it like this: `-ia ""/yo=""""Spaces spaces""""""`. In
   PowerShell.exe, you must pass it like this: `-ia '/yo=""""Spaces spaces""""'`.
   No other combination will work. In PowerShell.exe if you are on version
   v3+, you can try `--%` before `-ia` to just pass the args through as is,
   which means it should not require any special workarounds.
 * **Periods in PowerShell**: If you need to pass a period as part of a
   value or a path, PowerShell doesn't always handle it well. Please
   quote those values using ""Quote Values"" section above.
 * Options and switches apply to all items passed, so if you are
   installing multiple packages, and you use `--version=1.0.0`, choco
   is going to look for and try to install version 1.0.0 of every
   package passed. So please split out multiple package calls when
   wanting to pass specific options.
");
                "chocolatey".Log().Info(ChocolateyLoggers.Important, @"Scripting / Integration - Best Practices / Style Guide");
                "chocolatey".Log().Info(@"
When writing scripts, such as PowerShell scripts passing options and
switches, there are some best practices to follow to ensure that you
don't run into issues later. This also applies to integrations that
are calling Chocolatey and parsing output. Chocolatey **uses** 
PowerShell, but it is an exe, so it cannot return PowerShell objects.

Following these practices ensures both readability of your scripts AND 
compatibility across different versions and editions of Chocolatey. 
Following this guide will ensure your experience is not frustrating 
based on choco not receiving things you think you are passing to it.

 * For consistency, always use `choco`, not `choco.exe`. Never use 
   shortcut commands like `cinst` or `cup`.
 * Always have the command as the first argument to `choco. e.g.
   `choco install`, where `install` is the command.
 * If there is a subcommand, ensure that is the second argument. e.g.
   `choco source list`, where `source` is the command and `list` is the
   subcommand.
 * Typically the subject comes next. If installing packages, the 
   subject would be the package names, e.g. `choco install pkg1 pkg2`.
 * Never use 'nupkg' or point directly to a nupkg file UNLESS using
   'choco push'. Use the source folder instead, e.g. `choco install
   <package id> --source=""'c:\folder\with\package'""` instead of 
   `choco install DoNotDoThis.1.0.nupkg` or `choco install DoNotDoThis 
    --source=""'c:\folder\with\package\DoNotDoThis.1.0.nupkg'""`.
 * Switches and parameters are called simply options. Options come 
   after the subject. e.g. `choco install pkg1 --debug --verbose`.
 * Never use the force option (`--force`/`-f`) in scripts (or really
   otherwise as a default mode of use). Force is an override on 
   Chocolatey behavior. If you are wondering why Chocolatey isn't doing
   something like the documentation says it should, it's likely because
   you are using force. Stop.
 * Always use full option name. If the short option is `-n`, and the
   full option is `--name`, use `--name`. The only acceptable short
   option for use in scripts is `-y`. Find option names in help docs
   online or through `choco -?` /`choco [Command Name] -?`.
 * For scripts that are running automated, always use `-y`. Do note 
   that even with `-y` passed, some things / state issues detected will
   temporarily stop for input - the key here is temporarily. They will 
   continue without requiring any action after the temporary timeout
   (typically 30 seconds).
 * Full option names are prepended with two dashes, e.g. `--` or 
   `--debug --verbose --ignore-proxy`.
 * When setting a value to an option, always put an equals (`=`) 
   between the name and the setting, e.g. `--source=""'local'""`.
 * When setting a value to an option, always surround the value 
   properly with double quotes bookending apostrophes, e.g. 
   `--source=""'internal_server'""`.
 * If you are building PowerShell scripts, you can most likely just 
   simply use apostrophes surrounding option values, e.g. 
   `--source='internal_server'`.
 * Prefer upgrade to install in scripts. You can't `install` to a newer
   version of something, but you can `choco upgrade` which will do both
   upgrade or install (unless switched off explicitly).
 * If you are sharing the script with others, pass `--source` to be 
   explicit about where the package is coming from. Use full link and 
   not source name ('https://chocolatey.org/api/v2' versus 
   'chocolatey').
 * If parsing output, you might want to use `--limit-output`/`-r` to 
   get output in a more machine parseable format. NOTE: Not all 
   commands handle return of information in an easily digestible 
   output.
 * Use exit codes to determine status. Chocolatey exits with 0 when 
   everything worked appropriately and other exits codes like 1 when 
   things error. There are package specific exit codes that are 
   recommended to be used and reboot indicating exit codes as well. To
   check exit code when using PowerShell, immediately call 
   `$exitCode = $LASTEXITCODE` to get the value choco exited with.

Here's an example following bad practices (line breaks added for 
 readability):

  `choco install pkg1 -y -params '/Option:Value /Option2:value with 
   spaces' --c4b-option 'Yaass' --option-that-is-new 'dude upgrade'`

Now here is that example written with best practices (again line 
 breaks added for readability - there are not line continuations 
 for choco):

  `choco upgrade pkg1 -y --source=""'https://chocolatey.org/api/v2'"" 
   --package-parameters=""'/Option:Value /Option2:value with spaces'""
   --c4b-option=""'Yaass'"" --option-that-is-new=""'dude upgrade'""`

Note the differences between the two: 
 * Which is more self-documenting? 
 * Which will allow for the newest version of something installed or 
   upgraded to (which allows for more environmental consistency on
   packages and versions)?
 * Which may throw an error on a badly passed option?
 * Which will throw errors on unknown option values? See explanation 
   below.

Chocolatey ignores options it doesn't understand, but it can only
 ignore option values if they are tied to the option with an
 equals sign ('='). Note those last two options in the examples above?
 If you roll off of a commercial edition or someone with older version
 attempts to run the badly crafted script `--c4b-option 'Yaass'
 --option-that-is-new 'dude upgrade'`, they are likely to see errors on
 'Yaass' and 'dude upgrade' because they are not explicitly tied to the 
 option they are written after. Now compare that to the other script. 
 Choco will ignore `--c4b-option=""'Yaass'""` and
 `--option-that-is-new=""'dude upgrade'""` as a whole when it doesn't
 register the options. This means that your script doesn't error.

Following these scripting best practices will ensure your scripts work
 everywhere they are used and with newer versions of Chocolatey.

");
                "chocolatey".Log().Info(ChocolateyLoggers.Important, "Default Options and Switches");
            });
        }