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)); }); }
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 => { if (!ChocolateyOptionSet.Instance.Parse(commandArgs, command, config)) { 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(""); } } }); }
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)); }); }
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)); }); }