public override int Execute( CliController controller, string[] rawArgs, Dictionary <CliOption, object?> options, IReadOnlyCollection <string> unknownArgs) { if (options.Count == 0 && (rawArgs.Length == 0 || (rawArgs.Length == 1 && rawArgs[0] == "help"))) { // handle proper calls with general help display: // "dotnet linq2db" // "dotnet linq2db help" PrintGeneralHelp(controller, Array.Empty <string>()); return(StatusCodes.SUCCESS); } // handle command-specific help requests (except help command itself): // "dotnet linq2db help <known_command>" if (options.Count == 0 && rawArgs.Length == 2 && rawArgs[0] == "help") { foreach (var command in controller.Commands) { if (command != this) { if (command.Name == rawArgs[1]) { // request for command help for known non-help command - print specific command help PrintCommandHelp(command, unknownArgs); return(StatusCodes.SUCCESS); } } } // help request for unknown command: // dotnet linq2db help <unknown-command> PrintGeneralHelp(controller, new[] { rawArgs[1] }); return(StatusCodes.INVALID_ARGUMENTS); } // all other cases - print default help and error message: // "dotnet linq2db help <whatever> <arguments> <here>" PrintGeneralHelp(controller, rawArgs); return(StatusCodes.INVALID_ARGUMENTS); }
public override int Execute( CliController controller, string[] rawArgs, Dictionary <CliOption, object?> options, IReadOnlyCollection <string> unknownArgs) { // processed on controller level already options.Remove(General.Import); // scaffold settings object initialization var settings = ProcessScaffoldOptions(options); if (settings == null) { return(StatusCodes.INVALID_ARGUMENTS); } // restart if other arch requested if (options.Remove(General.Architecture, out var value) && RestartIfNeeded((string)value !, rawArgs, out var status)) { return(status.Value); } // process remaining utility-specific (general) options // output folder var output = Directory.GetCurrentDirectory(); if (options.Remove(General.Output, out value)) { output = (string)value !; } // overwrite existing files var overwrite = false; if (options.Remove(General.Overwrite, out value)) { overwrite = (bool)value !; } options.Remove(General.Provider, out value); var providerName = Enum.Parse <DatabaseType>((string)value !); var provider = providerName switch { DatabaseType.Access => ProviderName.Access, DatabaseType.DB2 => ProviderName.DB2, DatabaseType.Firebird => ProviderName.Firebird, DatabaseType.Informix => ProviderName.Informix, DatabaseType.SQLServer => ProviderName.SqlServer, DatabaseType.MySQL => ProviderName.MySql, DatabaseType.Oracle => ProviderName.Oracle, DatabaseType.PostgreSQL => ProviderName.PostgreSQL, DatabaseType.SqlCe => ProviderName.SqlCe, DatabaseType.SQLite => ProviderName.SQLite, DatabaseType.Sybase => ProviderName.Sybase, DatabaseType.SapHana => ProviderName.SapHana, _ => throw new InvalidOperationException($"Unsupported provider: {providerName}") }; options.Remove(General.ConnectionString, out value); var connectionString = (string)value !; options.Remove(General.ProviderLocation, out value); var providerLocation = (string?)value; options.Remove(General.AdditionalConnectionString, out value); var additionalConnectionString = (string?)value; options.Remove(General.Interceptors, out value); var interceptorsPath = (string?)value; // assert that all provided options handled if (options.Count > 0) { foreach (var kvp in options) { Console.Error.WriteLine($"{Name} command miss '{kvp.Key.Name}' option handler"); } // throw exception as it is implementation bug, not bad input or other expected error throw new InvalidOperationException($"Not all options handled by {Name} command"); } // load interceptors from T4 template or assembly ScaffoldInterceptors?interceptors = null; if (interceptorsPath != null) { (var res, interceptors) = LoadInterceptors(interceptorsPath, settings); if (res != StatusCodes.SUCCESS) { return(res); } } // perform scaffolding return(Scaffold(settings, interceptors, provider, providerLocation, connectionString, additionalConnectionString, output, overwrite)); }