public int Invoke(string[] args) { try { HelpCommand = new HelpCommand(Manager, "galops", "NuGet Gallery Operations", "https://github.com/NuGet/NuGetOperations/wiki/GalOps---Gallery-Operations-Commands"); // Add commands foreach (ICommand cmd in Commands) { Manager.RegisterCommand(cmd); } var secretReaderFactory = new SecretReaderFactory(ConfigurationManager.AppSettings); var configurationProcessor = new ConfigurationProcessor(secretReaderFactory); configurationProcessor.InjectSecretsInto(ConfigurationManager.AppSettings); // Parse the command var parser = new CommandLineParser(Manager, secretReaderFactory); ICommand command = parser.ParseCommandLine(args) ?? HelpCommand; // Fall back on help command if we failed to parse a valid command if (!ArgumentCountValid(command)) { string commandName = command.CommandAttribute.CommandName; Console.WriteLine("{0}: invalid arguments..", commandName); HelpCommand.ViewHelpForCommand(commandName); } else { command.Execute(); } } catch (AggregateException exception) { string message; Exception unwrappedEx = ExceptionUtility.Unwrap(exception); if (unwrappedEx == exception) { // If the AggregateException contains more than one InnerException, it cannot be unwrapped. In which case, simply print out individual error messages message = String.Join(Environment.NewLine, exception.InnerExceptions.Select(ex => ex.Message).Distinct(StringComparer.CurrentCulture)); } else { message = ExceptionUtility.Unwrap(exception).Message; } _logger.Error("{0}: {1}", unwrappedEx.GetType().Name, message); _logger.Error(" Stack Trace: " + unwrappedEx.StackTrace); return 1; } catch (Exception e) { var ex = ExceptionUtility.Unwrap(e); _logger.Error("{0}: {1}", ex.GetType().Name, ex.Message); _logger.Error(" Stack Trace: " + ex.StackTrace); return 1; } return 0; }
public static int Main(string[] args) { var console = new Common.Console(); var fileSystem = new PhysicalFileSystem(Directory.GetCurrentDirectory()); try { // Remove NuGet.exe.old RemoveOldFile(fileSystem); // Import Dependencies var p = new Program(); p.Initialize(fileSystem, console); // Add commands to the manager foreach (ICommand cmd in p.Commands) { p.Manager.RegisterCommand(cmd); } CommandLineParser parser = new CommandLineParser(p.Manager); // Parse the command ICommand command = parser.ParseCommandLine(args) ?? p.HelpCommand; // Fallback on the help command if we failed to parse a valid command if (!ArgumentCountValid(command)) { // Get the command name and add it to the argument list of the help command string commandName = command.CommandAttribute.CommandName; // Print invalid command then show help console.WriteLine(NuGetResources.InvalidArguments, commandName); p.HelpCommand.ViewHelpForCommand(commandName); } else { command.Execute(); } } catch (AggregateException exception) { if (ExceptionUtility.Unwrap(exception) == exception) { // If the AggregateException contains more than one InnerException, it cannot be unwrapped. In which case, simply print out individual error messages var messages = exception.InnerExceptions.Select(ex => ex.Message) .Distinct(StringComparer.CurrentCulture); console.WriteError(String.Join("\n", messages)); } } catch (Exception e) { console.WriteError(ExceptionUtility.Unwrap(e).Message); return 1; } return 0; }
public static int Main(string[] args) { var console = new NuGet.Common.Console(); var fileSystem = new PhysicalFileSystem(Directory.GetCurrentDirectory()); try { // Remove NuGet.exe.old RemoveOldFile(fileSystem); // Import Dependencies var p = new Program(); p.Initialize(fileSystem); // Register an additional provider for the console specific application so that the user // will be prompted if a proxy is set and credentials are required HttpClient.DefaultCredentialProvider = new ConsoleCredentialProvider(); // Add commands to the manager foreach (ICommand cmd in p.Commands) { p.Manager.RegisterCommand(cmd); } CommandLineParser parser = new CommandLineParser(p.Manager); // Parse the command ICommand command = parser.ParseCommandLine(args) ?? p.HelpCommand; // Fallback on the help command if we failed to parse a valid command if (!ArgumentCountValid(command)) { // Get the command name and add it to the argument list of the help command string commandName = command.CommandAttribute.CommandName; // Print invalid command then show help Console.WriteLine(NuGetResources.InvalidArguments, commandName); p.HelpCommand.ViewHelpForCommand(commandName); } else { command.Execute(); } } catch (Exception e) { console.WriteError(e.Message); return 1; } return 0; }
public static int Main(string[] args) { try { // Remove NuGet.exe.old RemoveOldFile(); // Import Dependecies var p = new Program(); p.Initialize(); // Add commands to the manager foreach (ICommand cmd in p.Commands) { p.Manager.RegisterCommand(cmd); } CommandLineParser parser = new CommandLineParser(p.Manager); // Parse the command ICommand command = parser.ParseCommandLine(args) ?? p.HelpCommand; // Fallback on the help command if we failed to parse a valid command if (!p.ArgumentCountValid(command)) { // Get the command name and add it to the argumet list of the help command string commandName = command.CommandAttribute.CommandName; // Print invalid command then show help Console.WriteLine(NuGet.Common.NuGetResources.InvalidArguments, commandName); p.HelpCommand.ViewHelpForCommand(commandName); } else { command.Execute(); } } catch (Exception e) { var currentColor = ConsoleColor.Gray; try { currentColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine(e.Message); } finally { Console.ForegroundColor = currentColor; } return 1; } return 0; }
public static int Main(string[] args) { DebugHelper.WaitForAttach(ref args); var console = new Common.Console(); var fileSystem = new PhysicalFileSystem(Directory.GetCurrentDirectory()); Func<Exception, string> getErrorMessage = e => e.Message; // When we're detailed, get the whole exception including the stack // This is useful for debugging errors. if (console.Verbosity == Verbosity.Detailed) { getErrorMessage = e => e.ToString(); } try { // Remove NuGet.exe.old RemoveOldFile(fileSystem); // Import Dependencies var p = new Program(); p.Initialize(fileSystem, console); // Add commands to the manager foreach (ICommand cmd in p.Commands) { p.Manager.RegisterCommand(cmd); } CommandLineParser parser = new CommandLineParser(p.Manager); // Parse the command ICommand command = parser.ParseCommandLine(args) ?? p.HelpCommand; // Fallback on the help command if we failed to parse a valid command if (!ArgumentCountValid(command)) { // Get the command name and add it to the argument list of the help command string commandName = command.CommandAttribute.CommandName; // Print invalid command then show help console.WriteLine(NuGetResources.InvalidArguments, commandName); p.HelpCommand.ViewHelpForCommand(commandName); } else { SetConsoleInteractivity(console, command as Command); command.Execute(); } } catch (AggregateException exception) { string message; Exception unwrappedEx = ExceptionUtility.Unwrap(exception); if (unwrappedEx == exception) { // If the AggregateException contains more than one InnerException, it cannot be unwrapped. In which case, simply print out individual error messages message = String.Join(Environment.NewLine, exception.InnerExceptions.Select(getErrorMessage).Distinct(StringComparer.CurrentCulture)); } else { message = getErrorMessage(ExceptionUtility.Unwrap(exception)); } console.WriteError(message); return 1; } catch (Exception e) { console.WriteError(getErrorMessage(ExceptionUtility.Unwrap(e))); return 1; } return 0; }
public static int Main(string[] args) { DebugHelper.WaitForAttach(ref args); // This is to avoid applying weak event pattern usage, which breaks under Mono or restricted environments, e.g. Windows Azure Web Sites. EnvironmentUtility.SetRunningFromCommandLine(); // set output encoding to UTF8 if -utf8 is specified var oldOutputEncoding = System.Console.OutputEncoding; if (args.Any(arg => String.Equals(arg, "-utf8", StringComparison.OrdinalIgnoreCase))) { args = args.Where(arg => !String.Equals(arg, "-utf8", StringComparison.OrdinalIgnoreCase)).ToArray(); SetConsoleOutputEncoding(System.Text.Encoding.UTF8); } var console = new Common.Console(); var fileSystem = new PhysicalFileSystem(Directory.GetCurrentDirectory()); Func<Exception, string> getErrorMessage = e => e.Message; try { // Remove NuGet.exe.old RemoveOldFile(fileSystem); // Import Dependencies var p = new Program(); p.Initialize(fileSystem, console); // Add commands to the manager foreach (ICommand cmd in p.Commands) { p.Manager.RegisterCommand(cmd); } CommandLineParser parser = new CommandLineParser(p.Manager); // Parse the command ICommand command = parser.ParseCommandLine(args) ?? p.HelpCommand; // Fallback on the help command if we failed to parse a valid command if (!ArgumentCountValid(command)) { // Get the command name and add it to the argument list of the help command string commandName = command.CommandAttribute.CommandName; // Print invalid command then show help console.WriteLine(LocalizedResourceManager.GetString("InvalidArguments"), commandName); p.HelpCommand.ViewHelpForCommand(commandName); } else { SetConsoleInteractivity(console, command as Command); // When we're detailed, get the whole exception including the stack // This is useful for debugging errors. if (console.Verbosity == Verbosity.Detailed) { getErrorMessage = e => e.ToString(); } command.Execute(); } } catch (AggregateException exception) { string message; Exception unwrappedEx = ExceptionUtility.Unwrap(exception); if (unwrappedEx == exception) { // If the AggregateException contains more than one InnerException, it cannot be unwrapped. In which case, simply print out individual error messages message = String.Join(Environment.NewLine, exception.InnerExceptions.Select(getErrorMessage).Distinct(StringComparer.CurrentCulture)); } else { message = getErrorMessage(ExceptionUtility.Unwrap(exception)); } console.WriteError(message); return 1; } catch (Exception e) { console.WriteError(getErrorMessage(ExceptionUtility.Unwrap(e))); return 1; } finally { OptimizedZipPackage.PurgeCache(); SetConsoleOutputEncoding(oldOutputEncoding); } return 0; }
public static int Main(string[] args) { DebugHelper.WaitForAttach(ref args); // This is to avoid applying weak event pattern usage, which breaks under Mono or restricted environments, e.g. Windows Azure Web Sites. EnvironmentUtility.SetRunningFromCommandLine(); // set output encoding to UTF8 if -utf8 is specified var oldOutputEncoding = System.Console.OutputEncoding; if (args.Any(arg => String.Equals(arg, "-utf8", StringComparison.OrdinalIgnoreCase))) { args = args.Where(arg => !String.Equals(arg, "-utf8", StringComparison.OrdinalIgnoreCase)).ToArray(); SetConsoleOutputEncoding(System.Text.Encoding.UTF8); } var console = new Common.Console(); var fileSystem = new PhysicalFileSystem(Directory.GetCurrentDirectory()); Func <Exception, string> getErrorMessage = e => e.Message; try { // Remove NuGet.exe.old RemoveOldFile(fileSystem); // Import Dependencies var p = new Program(); p.Initialize(fileSystem, console); // Add commands to the manager foreach (ICommand cmd in p.Commands) { p.Manager.RegisterCommand(cmd); } CommandLineParser parser = new CommandLineParser(p.Manager); // Parse the command ICommand command = parser.ParseCommandLine(args) ?? p.HelpCommand; // Fallback on the help command if we failed to parse a valid command if (!ArgumentCountValid(command)) { // Get the command name and add it to the argument list of the help command string commandName = command.CommandAttribute.CommandName; // Print invalid command then show help console.WriteLine(LocalizedResourceManager.GetString("InvalidArguments"), commandName); p.HelpCommand.ViewHelpForCommand(commandName); } else { SetConsoleInteractivity(console, command as Command); // When we're detailed, get the whole exception including the stack // This is useful for debugging errors. if (console.Verbosity == Verbosity.Detailed) { getErrorMessage = e => e.ToString(); } command.Execute(); } } catch (AggregateException exception) { string message; Exception unwrappedEx = ExceptionUtility.Unwrap(exception); if (unwrappedEx == exception) { // If the AggregateException contains more than one InnerException, it cannot be unwrapped. In which case, simply print out individual error messages message = String.Join(Environment.NewLine, exception.InnerExceptions.Select(getErrorMessage).Distinct(StringComparer.CurrentCulture)); } else { message = getErrorMessage(ExceptionUtility.Unwrap(exception)); } console.WriteError(message); return(1); } catch (Exception e) { console.WriteError(getErrorMessage(ExceptionUtility.Unwrap(e))); return(1); } finally { OptimizedZipPackage.PurgeCache(); SetConsoleOutputEncoding(oldOutputEncoding); } return(0); }
public static int Main(string[] args) { DebugHelper.WaitForAttach(ref args); var console = new Common.Console(); var fileSystem = new PhysicalFileSystem(Directory.GetCurrentDirectory()); Func <Exception, string> getErrorMessage = e => e.Message; try { // Remove NuGet.exe.old RemoveOldFile(fileSystem); // Import Dependencies var p = new Program(); p.Initialize(fileSystem, console); // Add commands to the manager foreach (ICommand cmd in p.Commands) { p.Manager.RegisterCommand(cmd); } CommandLineParser parser = new CommandLineParser(p.Manager); // Parse the command ICommand command = parser.ParseCommandLine(args) ?? p.HelpCommand; // Fallback on the help command if we failed to parse a valid command if (!ArgumentCountValid(command)) { // Get the command name and add it to the argument list of the help command string commandName = command.CommandAttribute.CommandName; // Print invalid command then show help console.WriteLine(NuGetResources.InvalidArguments, commandName); p.HelpCommand.ViewHelpForCommand(commandName); } else { SetConsoleInteractivity(console, command as Command); // When we're detailed, get the whole exception including the stack // This is useful for debugging errors. if (console.Verbosity == Verbosity.Detailed) { getErrorMessage = e => e.ToString(); } command.Execute(); } } catch (AggregateException exception) { string message; Exception unwrappedEx = ExceptionUtility.Unwrap(exception); if (unwrappedEx == exception) { // If the AggregateException contains more than one InnerException, it cannot be unwrapped. In which case, simply print out individual error messages message = String.Join(Environment.NewLine, exception.InnerExceptions.Select(getErrorMessage).Distinct(StringComparer.CurrentCulture)); } else { message = getErrorMessage(ExceptionUtility.Unwrap(exception)); } console.WriteError(message); return(1); } catch (Exception e) { console.WriteError(getErrorMessage(ExceptionUtility.Unwrap(e))); return(1); } finally { OptimizedZipPackage.PurgeCache(); } return(0); }