public static int Main(string[] args) { if (!AssignCommand(args)) { ShowUsage(); return(1); } var configuration = new ConfigurationBuilder().AddCommandLine(args).Build(); var options = new ToolOptions(); configuration.Bind(options); Func <ParsedToolOptions, ICommand> commandCreator = null; var(isValid, errorMessage, parsedOptions) = new ToolOptionsParser(options).Parse(); if (isValid) { if (!_commandMap.TryGetValue(parsedOptions.Command, out commandCreator)) { isValid = false; errorMessage = $"Cannot find implementation for command {parsedOptions.Command}."; } } if (!isValid) { Console.WriteLine(errorMessage); Console.WriteLine(); ShowUsage(); return(1); } try { commandCreator(parsedOptions).Run(); } catch (Exception ex) { Console.WriteLine($"ERROR: {ex.Message}"); return(1); } return(0); }
public ToolOptionsParser(ToolOptions options) => _options = options;