Skip to content

Commit

Permalink
A cleaner, ordered config file for the CLI (#2170)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikEJ authored Feb 17, 2024
1 parent 1d6097c commit f3b4d46
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 83 deletions.
11 changes: 7 additions & 4 deletions src/GUI/RevEng.Shared/Cli/CliConfigMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,12 @@ private static List<string> ValidateExcludedColumns(CliConfig config, List<Table
{
List<string> warnings = new();

var objectsToCheck = config.Tables.Where(x => x.ExcludedColumns?.Count > 0)
var tables = config.Tables ?? new List<Table>();
var views = config.Views ?? new List<View>();

var objectsToCheck = tables.Where(x => x.ExcludedColumns?.Count > 0)
.Select(table => table as IEntity)
.Union(config.Views.Where(x => x.ExcludedColumns?.Count > 0));
.Union(views.Where(x => x.ExcludedColumns?.Count > 0));

foreach (var table in objectsToCheck)
{
Expand Down Expand Up @@ -324,7 +327,7 @@ private static List<T> Add<T>(IEnumerable<TableModel> models, List<T> entities)
var newItems = models.Where(o => o.ObjectType == objectType).ToList();
if (newItems.Count == 0)
{
return new List<T>();
return null;
}

var result = entities ?? new List<T>();
Expand All @@ -339,7 +342,7 @@ private static List<T> Add<T>(IEnumerable<TableModel> models, List<T> entities)
}
}

return result;
return result.Count > 0 ? result : null;
}

private static ObjectType DefineObjectType<T>()
Expand Down
37 changes: 24 additions & 13 deletions src/GUI/RevEng.Shared/Cli/Configuration/CliConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,54 @@ namespace RevEng.Common.Cli.Configuration
#pragma warning disable CA2227
public class CliConfig
{
[JsonPropertyOrder(-1)]
[JsonPropertyName("$schema")]
#pragma warning disable CA1822
public string JsonSchema =>
"https://raw.githubusercontent.com/ErikEJ/EFCorePowerTools/master/samples/efcpt-schema.json";
#pragma warning restore CA1822

[JsonPropertyOrder(10)]
[JsonPropertyName("code-generation")]
public CodeGeneration CodeGeneration { get; set; } = new CodeGeneration();

[JsonPropertyName("names")]
public Names Names { get; set; } = new Names();

[JsonPropertyOrder(20)]
[JsonPropertyName("file-layout")]
public FileLayout FileLayout { get; set; } = new FileLayout();

[JsonPropertyName("type-mappings")]
[JsonPropertyOrder(30)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public TypeMappings TypeMappings { get; set; }
[JsonPropertyName("functions")]
public List<Function> Functions { get; set; }

[JsonPropertyOrder(40)]
[JsonPropertyName("names")]
public Names Names { get; set; } = new Names();

[JsonPropertyOrder(50)]
[JsonPropertyName("replacements")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public Replacements Replacements { get; set; }

[JsonPropertyName("tables")]
[JsonPropertyOrder(60)]
[JsonPropertyName("stored-procedures")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public List<Table> Tables { get; set; }
public List<StoredProcedure> StoredProcedures { get; set; }

[JsonPropertyName("views")]
[JsonPropertyOrder(70)]
[JsonPropertyName("tables")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public List<View> Views { get; set; }
public List<Table> Tables { get; set; }

[JsonPropertyName("stored-procedures")]
[JsonPropertyOrder(80)]
[JsonPropertyName("type-mappings")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public List<StoredProcedure> StoredProcedures { get; set; }
public TypeMappings TypeMappings { get; set; }

[JsonPropertyOrder(90)]
[JsonPropertyName("views")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("functions")]
public List<Function> Functions { get; set; }
public List<View> Views { get; set; }
}
#pragma warning restore CA2227
}
88 changes: 54 additions & 34 deletions src/GUI/RevEng.Shared/Cli/Configuration/CodeGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,86 @@ namespace RevEng.Common.Cli.Configuration
{
public class CodeGeneration
{
[JsonPropertyOrder(10)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("discover-multiple-stored-procedure-resultsets-preview")]
public bool DiscoverMultipleStoredProcedureResultsetsPreview { get; set; }

[JsonPropertyOrder(20)]
[JsonPropertyName("enable-on-configuring")]
public bool EnableOnConfiguring { get; set; }

[JsonPropertyOrder(30)]
[JsonPropertyName("generate-mermaid-diagram")]
public bool GenerateMermaidDiagram { get; set; }

[JsonPropertyOrder(40)]
[JsonPropertyName("merge-dacpacs")]
public bool MergeDacpacs { get; set; }

[JsonPropertyOrder(50)]
[JsonPropertyName("refresh-object-lists")]
public bool RefreshObjectLists { get; set; } = true;

[JsonPropertyOrder(60)]
[JsonPropertyName("remove-defaultsql-from-bool-properties")]
public bool RemoveDefaultSqlFromBoolProperties { get; set; }

[JsonPropertyOrder(70)]
[JsonPropertyName("soft-delete-obsolete-files")]
public bool SoftDeleteObsoleteFiles { get; set; } = true;

[JsonPropertyOrder(80)]
[JsonPropertyName("t4-template-path")]
public string T4TemplatePath { get; set; }

[JsonPropertyOrder(90)]
[JsonPropertyName("type")]
public string Type { get; set; } = "all";

[JsonPropertyName("use-database-names")]
public bool UseDatabaseNames { get; set; }
[JsonPropertyOrder(100)]
[JsonPropertyName("use-alternate-stored-procedure-resultset-discovery")]
public bool UseAlternateStoredProcedureResultsetDiscovery { get; set; }

[JsonPropertyOrder(110)]
[JsonPropertyName("use-data-annotations")]
public bool UseDataAnnotations { get; set; }

[JsonPropertyName("use-nullable-reference-types")]
public bool UseNullableReferenceTypes { get; set; } = true;
[JsonPropertyOrder(120)]
[JsonPropertyName("use-database-names")]
public bool UseDatabaseNames { get; set; }

[JsonPropertyOrder(130)]
[JsonPropertyName("use-decimal-data-annotation-for-sproc-results")]
public bool UseDecimalDataAnnotation { get; set; } = true;

[JsonPropertyOrder(140)]
[JsonPropertyName("use-inflector")]
public bool UseInflector { get; set; } = true;

[JsonPropertyOrder(150)]
[JsonPropertyName("use-legacy-inflector")]
public bool UseLegacyInflector { get; set; }

[JsonPropertyOrder(160)]
[JsonPropertyName("use-many-to-many-entity")]
public bool UseManyToManyEntity { get; set; }

[JsonPropertyName("use-t4")]
public bool UseT4 { get; set; }

[JsonPropertyName("t4-template-path")]
public string T4TemplatePath { get; set; }

[JsonPropertyName("remove-defaultsql-from-bool-properties")]
public bool RemoveDefaultSqlFromBoolProperties { get; set; }

[JsonPropertyName("soft-delete-obsolete-files")]
public bool SoftDeleteObsoleteFiles { get; set; } = true;

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("discover-multiple-stored-procedure-resultsets-preview")]
public bool DiscoverMultipleStoredProcedureResultsetsPreview { get; set; }

[JsonPropertyName("use-alternate-stored-procedure-resultset-discovery")]
public bool UseAlternateStoredProcedureResultsetDiscovery { get; set; }

[JsonPropertyOrder(170)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("use-no-navigations-preview")]
public bool UseNoNavigationsPreview { get; set; }

[JsonPropertyName("merge-dacpacs")]
public bool MergeDacpacs { get; set; }

[JsonPropertyName("use-decimal-data-annotation-for-sproc-results")]
public bool UseDecimalDataAnnotation { get; set; } = true;

[JsonPropertyName("generate-mermaid-diagram")]
public bool GenerateMermaidDiagram { get; set; }

[JsonPropertyName("refresh-object-lists")]
public bool RefreshObjectLists { get; set; } = true;
[JsonPropertyOrder(180)]
[JsonPropertyName("use-nullable-reference-types")]
public bool UseNullableReferenceTypes { get; set; } = true;

[JsonPropertyOrder(190)]
[JsonPropertyName("use-prefix-navigation-naming")]
public bool UsePrefixNavigationNaming { get; set; }

[JsonPropertyOrder(200)]
[JsonPropertyName("use-t4")]
public bool UseT4 { get; set; }
}
}
11 changes: 8 additions & 3 deletions src/GUI/RevEng.Shared/Cli/Configuration/FileLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@ namespace RevEng.Common.Cli.Configuration
{
public class FileLayout
{
[JsonPropertyName("output-path")]
public string OutputPath { get; set; } = "Models";

[JsonPropertyOrder(10)]
[JsonPropertyName("output-dbcontext-path")]
public string OutputDbContextPath { get; set; }

[JsonPropertyOrder(20)]
[JsonPropertyName("output-path")]
public string OutputPath { get; set; } = "Models";

[JsonPropertyOrder(30)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("split-dbcontext-preview")]
public bool SplitDbContextPreview { get; set; }

[JsonPropertyOrder(40)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("use-schema-folders-preview")]
public bool UseSchemaFoldersPreview { get; set; }

[JsonPropertyOrder(50)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("use-schema-namespaces-preview")]
public bool UseSchemaNamespacesPreview { get; set; }
Expand Down
11 changes: 7 additions & 4 deletions src/GUI/RevEng.Shared/Cli/Configuration/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ namespace RevEng.Common.Cli.Configuration
public class Function : IEntity
#pragma warning restore CA1716 // Identifiers should not match keywords
{
[JsonPropertyName("name")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string Name { get; set; }

[JsonPropertyOrder(10)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("exclude")]
public bool? Exclude { get; set; }

[JsonPropertyOrder(20)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("exclusionWildcard")]
public string ExclusionWildcard { get; set; }

[JsonPropertyOrder(30)]
[JsonPropertyName("name")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string Name { get; set; }

[JsonIgnore]
public List<string> ExcludedColumns { get; set; } = null;
}
Expand Down
10 changes: 7 additions & 3 deletions src/GUI/RevEng.Shared/Cli/Configuration/Names.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ namespace RevEng.Common.Cli.Configuration
{
public class Names
{
[JsonPropertyName("root-namespace")]
public string RootNamespace { get; set; }

[JsonPropertyOrder(10)]
[JsonPropertyName("dbcontext-name")]
public string DbContextName { get; set; }

[JsonPropertyOrder(20)]
[JsonPropertyName("dbcontext-namespace")]
public string DbContextNamespace { get; set; }

[JsonPropertyOrder(30)]
[JsonPropertyName("model-namespace")]
public string ModelNamespace { get; set; }

[JsonPropertyOrder(40)]
[JsonPropertyName("root-namespace")]
public string RootNamespace { get; set; }
}
}
3 changes: 3 additions & 0 deletions src/GUI/RevEng.Shared/Cli/Configuration/Replacements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ namespace RevEng.Common.Cli.Configuration
{
public class Replacements
{
[JsonPropertyOrder(10)]
[JsonPropertyName("preserve-casing-with-regex")]
public bool PreserveCasingWithRegex { get; set; }

[JsonPropertyOrder(20)]
[JsonPropertyName("uncountable-words")]
#pragma warning disable CA1819
public string[] UncountableWords { get; set; }
Expand Down
21 changes: 13 additions & 8 deletions src/GUI/RevEng.Shared/Cli/Configuration/StoredProcedure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,30 @@ namespace RevEng.Common.Cli.Configuration
{
public class StoredProcedure : IEntity
{
[JsonPropertyName("name")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string Name { get; set; }

[JsonPropertyOrder(10)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("exclude")]
public bool? Exclude { get; set; }

[JsonPropertyOrder(20)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("use-legacy-resultset-discovery")]
public bool UseLegacyResultsetDiscovery { get; set; }
[JsonPropertyName("exclusionWildcard")]
public string ExclusionWildcard { get; set; }

[JsonPropertyOrder(30)]
[JsonPropertyName("mapped-type")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string MappedType { get; set; }

[JsonPropertyOrder(40)]
[JsonPropertyName("name")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("exclusionWildcard")]
public string ExclusionWildcard { get; set; }
public string Name { get; set; }

[JsonPropertyOrder(50)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("use-legacy-resultset-discovery")]
public bool UseLegacyResultsetDiscovery { get; set; }

[JsonIgnore]
public List<string> ExcludedColumns { get; set; }
Expand Down
16 changes: 10 additions & 6 deletions src/GUI/RevEng.Shared/Cli/Configuration/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@ namespace RevEng.Common.Cli.Configuration
{
public class Table : IEntity
{
[JsonPropertyName("name")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string Name { get; set; }

[JsonPropertyOrder(10)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("exclude")]
public bool? Exclude { get; set; }

[JsonPropertyOrder(20)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("excludedColumns")]
public List<string> ExcludedColumns { get; set; } = null;

[JsonPropertyOrder(30)]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("exclusionWildcard")]
public string ExclusionWildcard { get; set; }

[JsonPropertyOrder(40)]
[JsonPropertyName("name")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
[JsonPropertyName("excludedColumns")]
public List<string> ExcludedColumns { get; set; } = null;
public string Name { get; set; }
}
}
Loading

0 comments on commit f3b4d46

Please sign in to comment.